Comments (4)
For this to work out, there would need to be two traits. IntoRequest
and IntoStreamingRequest
. Otherwise, you get into coherence problems.
Sketch:
struct Request<T>(T);
trait Message: std::fmt::Display {}
impl Message for &'static str {}
trait IntoRequest {
type Message: Message;
fn into_request(self) -> Request<Self::Message>;
}
trait IntoStreamingRequest {
type Stream: Iterator<Item = Self::Message>;
type Message: Message;
fn into_streaming_request(self) -> Request<Self::Stream>;
}
impl<T: Message> IntoRequest for Request<T> {
type Message = T;
fn into_request(self) -> Self {
self
}
}
impl<T: Iterator> IntoStreamingRequest for Request<T> where T::Item: Message {
type Stream = T;
type Message = T::Item;
fn into_streaming_request(self) -> Self {
self
}
}
impl<T: Iterator> IntoStreamingRequest for T where T::Item: Message {
type Stream = T;
type Message = T::Item;
fn into_streaming_request(self) -> Request<Self> {
Request(self)
}
}
fn say_hello<T: IntoStreamingRequest<Message = &'static str>>(t: T) {
println!("== say hello");
for msg in t.into_streaming_request().0 {
println!(" + {}", msg);
}
}
fn main() {
say_hello(vec!["hello", "world"].into_iter());
say_hello(Request(vec!["hello", "world"].into_iter()));
}
from tonic.
Hey! I'm fairly new to this project, but the library seems fantastic so far!
This looks like a nice first issue. I was hoping to take a crack at it sometime this week or over the weekend if a PR is welcome. 😃
from tonic.
@ChetanBhasin I'm not sure if this is actually going to be easy, or even possible — I took a crack at it earlier, and ran into some issues with type inference. If you want to take a look at it, you may have more success than I did, but I just wanted to warn you.
from tonic.
Oh, the solution of adding a separate trait for streaming requests is obvious in hindsight, nice!
from tonic.
Related Issues (20)
- Content-Type Validation Missing: Requests Not Returning HTTP 415 When Content-Type Is Not Start with `application/grpc`
- http2_keep_alive_interval doesn't work HOT 3
- Current "uds" example does not compile HOT 3
- Release 0.12.0 HOT 6
- `tonic::transport::Channel` struct is not as safe to clone for parallel use HOT 2
- Error when building excamples
- how to manually fail a client streaming?
- Add debug spans for codec tracing
- test codec::prost::tests::encode_too_big panicks on 32-bit architectures
- Inserting metadata in a test panics with index out of bounds HOT 2
- Tonic 0.12.0 compiles tokio even when no features are enabled HOT 4
- Upgrading to tonic-reflection 0.12 breaks reflection HOT 2
- use of undeclared crate or module `tonic_reflection` HOT 2
- How does tonic library dynamically set up custom middleware HOT 1
- Naming collisions with std::marker::Sync/Send
- How to make tonic support tls HOT 3
- nit: inconsistent use of crate::Error vs Error in single transport src file
- calling grpc server hosted on cloud run with https fails with transport error HOT 2
- version 0.12.1 causes ClientTlsConfig to explode with invalid CryptoProvider HOT 1
- Configuring Timeout for Graceful Shutdown HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tonic.