From 874dca3843f02025eec9003cfe716a58830ddfc3 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Fri, 16 Aug 2019 14:59:38 -0400 Subject: [PATCH] Fix async-stream dep --- tonic/Cargo.toml | 2 +- tonic/src/codec.rs | 9 ++++++--- tonic/tests/server.rs | 30 ++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 4300db4..63ee16f 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -18,7 +18,7 @@ prost = "0.5" percent-encoding = "1.0.1" tower-service = { git = "https://github.com/tower-rs/tower", branch = "std-future" } tokio-codec = "=0.2.0-alpha.1" -async-stream = { path = "../../async-stream/async-stream" } +async-stream = "0.1.0" http-body = { git = "https://github.com/hyperium/http-body", branch = "std-future" } [dev-dependencies] diff --git a/tonic/src/codec.rs b/tonic/src/codec.rs index c166218..52d5b6f 100644 --- a/tonic/src/codec.rs +++ b/tonic/src/codec.rs @@ -57,11 +57,14 @@ where } } -pub fn decode(mut decoder: T, mut source: B) -> impl TryStream +pub fn decode( + mut decoder: T, + mut source: B, +) -> impl TryStream + 'static where - T: Decoder, + T: Decoder + 'static, T::Item: Unpin + 'static, - B: Body, + B: Body + 'static, B::Error: Into, { stream! { diff --git a/tonic/tests/server.rs b/tonic/tests/server.rs index 05c23d2..38bd6ac 100644 --- a/tonic/tests/server.rs +++ b/tonic/tests/server.rs @@ -3,40 +3,50 @@ use std::future::Future; use std::task::{Context, Poll}; use tokio_buf::BufStream; -use tonic::codec::UnitCodec; +use tonic::codec::ProstCodec; use tonic::server::*; use tonic::{Request, Response, Status}; use std::pin::Pin; use futures_core::Stream; -type BoxStream = Pin> + Send + 'static>>; +#[derive(Clone, PartialEq, prost::Message)] +pub struct HelloRequest { + #[prost(string, tag = "1")] + pub name: std::string::String, +} +/// The response message containing the greetings +#[derive(Clone, PartialEq, prost::Message)] +pub struct HelloReply { + #[prost(string, tag = "1")] + pub message: std::string::String, +} struct SayHello; -impl UnaryService<()> for SayHello { - type Response = (); +impl UnaryService for SayHello { + type Response = HelloReply; type Future = impl Future, Status>>; - fn call(&mut self, _request: Request<()>) -> Self::Future { - async move { Ok(Response::new(())) } + fn call(&mut self, _request: Request) -> Self::Future { + async move { Ok(Response::new(HelloReply { message: "hello".into()})) } } } struct SayHelloStream; impl ClientStreamingService for SayHelloStream -where S: Stream{ - type Response = (); +where S: Stream> + Unpin + Send + 'static { + type Response = HelloReply; type Future = impl Future, Status>>; fn call(&mut self, _: Request) -> Self::Future { - async move { Ok(Response::new(())) } + async move { Ok(Response::new(HelloReply { message: "hello".into()})) } } } #[tokio::test] async fn say_hello() { - let codec = UnitCodec::default(); + let codec = ProstCodec::new(); let mut grpc = Grpc::new(codec); let request = http::Request::new(Body(Vec::new()));