From 79b82381ec5341145b065603afc848b53ad432ce Mon Sep 17 00:00:00 2001 From: Juan Alvarez Date: Sat, 16 Nov 2019 17:38:29 -0600 Subject: [PATCH 1/2] remove VecDeque from examples --- tonic-examples/src/authentication/server.rs | 4 ++-- tonic-examples/src/lib.rs | 15 +++++++++++++++ tonic-examples/src/load_balance/server.rs | 5 +++-- tonic-examples/src/multiplex/server.rs | 6 +++--- tonic-examples/src/tls/server.rs | 4 ++-- tonic-examples/src/tls_client_auth/server.rs | 5 ++--- 6 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 tonic-examples/src/lib.rs diff --git a/tonic-examples/src/authentication/server.rs b/tonic-examples/src/authentication/server.rs index cf49da0c0..6f34cbc2e 100644 --- a/tonic-examples/src/authentication/server.rs +++ b/tonic-examples/src/authentication/server.rs @@ -3,12 +3,12 @@ pub mod pb { } use pb::{EchoRequest, EchoResponse}; -use std::collections::VecDeque; use tonic::{body::BoxBody, transport::Server, Request, Response, Status, Streaming}; +use tonic_examples::ResponseStream; use tower::Service; type EchoResult = Result, Status>; -type Stream = VecDeque>; +type Stream = ResponseStream>; #[derive(Default)] pub struct EchoServer; diff --git a/tonic-examples/src/lib.rs b/tonic-examples/src/lib.rs new file mode 100644 index 000000000..d18ec154f --- /dev/null +++ b/tonic-examples/src/lib.rs @@ -0,0 +1,15 @@ +use futures::Stream; +use std::pin::Pin; +use std::task::{Context, Poll}; + +// A dummy Stream implementation for examples that require +// a Stream type but don't actually use it. +pub struct ResponseStream(T); + +impl Stream for ResponseStream { + type Item = T; + + fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { + unimplemented!() + } +} diff --git a/tonic-examples/src/load_balance/server.rs b/tonic-examples/src/load_balance/server.rs index ee68be498..0c07b211d 100644 --- a/tonic-examples/src/load_balance/server.rs +++ b/tonic-examples/src/load_balance/server.rs @@ -3,12 +3,13 @@ pub mod pb { } use pb::{EchoRequest, EchoResponse}; -use std::{collections::VecDeque, net::SocketAddr}; +use std::net::SocketAddr; use tokio::sync::mpsc; use tonic::{transport::Server, Request, Response, Status, Streaming}; +use tonic_examples::ResponseStream; type EchoResult = Result, Status>; -type Stream = VecDeque>; +type Stream = ResponseStream>; #[derive(Debug)] pub struct EchoServer { diff --git a/tonic-examples/src/multiplex/server.rs b/tonic-examples/src/multiplex/server.rs index a8af6e4af..e87c0ec7c 100644 --- a/tonic-examples/src/multiplex/server.rs +++ b/tonic-examples/src/multiplex/server.rs @@ -1,5 +1,5 @@ -use std::collections::VecDeque; use tonic::{transport::Server, Request, Response, Status}; +use tonic_examples::ResponseStream; pub mod hello_world { tonic::include_proto!("helloworld"); @@ -64,6 +64,6 @@ impl Echo for MyEcho { Ok(Response::new(EchoResponse { message })) } - type ServerStreamingEchoStream = VecDeque>; - type BidirectionalStreamingEchoStream = VecDeque>; + type ServerStreamingEchoStream = ResponseStream>; + type BidirectionalStreamingEchoStream = ResponseStream>; } diff --git a/tonic-examples/src/tls/server.rs b/tonic-examples/src/tls/server.rs index 2643fd419..7e27f5bdc 100644 --- a/tonic-examples/src/tls/server.rs +++ b/tonic-examples/src/tls/server.rs @@ -3,14 +3,14 @@ pub mod pb { } use pb::{EchoRequest, EchoResponse}; -use std::collections::VecDeque; use tonic::{ transport::{Identity, Server, ServerTlsConfig}, Request, Response, Status, Streaming, }; +use tonic_examples::ResponseStream; type EchoResult = Result, Status>; -type Stream = VecDeque>; +type Stream = ResponseStream>; #[derive(Default)] pub struct EchoServer; diff --git a/tonic-examples/src/tls_client_auth/server.rs b/tonic-examples/src/tls_client_auth/server.rs index 7ee7f2dd0..7491eb3c7 100644 --- a/tonic-examples/src/tls_client_auth/server.rs +++ b/tonic-examples/src/tls_client_auth/server.rs @@ -2,14 +2,13 @@ pub mod pb { tonic::include_proto!("grpc.examples.echo"); } -use std::collections::VecDeque; - use pb::{EchoRequest, EchoResponse}; use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig}; use tonic::{Request, Response, Status}; +use tonic_examples::ResponseStream; type EchoResult = Result, Status>; -type Stream = VecDeque>; +type Stream = ResponseStream>; #[derive(Default)] pub struct EchoServer; From c3e717b51a610ef122b770ea40ec085ec825df73 Mon Sep 17 00:00:00 2001 From: Juan Alvarez Date: Sun, 17 Nov 2019 11:41:48 -0600 Subject: [PATCH 2/2] remove dummy Stream implementation --- tonic-examples/src/authentication/server.rs | 9 +++++---- tonic-examples/src/lib.rs | 15 --------------- tonic-examples/src/load_balance/server.rs | 12 +++++++----- tonic-examples/src/multiplex/server.rs | 9 ++++++--- tonic-examples/src/tls/server.rs | 9 +++++---- tonic-examples/src/tls_client_auth/server.rs | 9 +++++---- 6 files changed, 28 insertions(+), 35 deletions(-) delete mode 100644 tonic-examples/src/lib.rs diff --git a/tonic-examples/src/authentication/server.rs b/tonic-examples/src/authentication/server.rs index 6f34cbc2e..006f4458a 100644 --- a/tonic-examples/src/authentication/server.rs +++ b/tonic-examples/src/authentication/server.rs @@ -2,13 +2,14 @@ pub mod pb { tonic::include_proto!("grpc.examples.echo"); } +use futures::Stream; use pb::{EchoRequest, EchoResponse}; +use std::pin::Pin; use tonic::{body::BoxBody, transport::Server, Request, Response, Status, Streaming}; -use tonic_examples::ResponseStream; use tower::Service; type EchoResult = Result, Status>; -type Stream = ResponseStream>; +type ResponseStream = Pin> + Send + Sync>>; #[derive(Default)] pub struct EchoServer; @@ -20,7 +21,7 @@ impl pb::server::Echo for EchoServer { Ok(Response::new(EchoResponse { message })) } - type ServerStreamingEchoStream = Stream; + type ServerStreamingEchoStream = ResponseStream; async fn server_streaming_echo( &self, @@ -36,7 +37,7 @@ impl pb::server::Echo for EchoServer { Err(Status::unimplemented("not implemented")) } - type BidirectionalStreamingEchoStream = Stream; + type BidirectionalStreamingEchoStream = ResponseStream; async fn bidirectional_streaming_echo( &self, diff --git a/tonic-examples/src/lib.rs b/tonic-examples/src/lib.rs deleted file mode 100644 index d18ec154f..000000000 --- a/tonic-examples/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -use futures::Stream; -use std::pin::Pin; -use std::task::{Context, Poll}; - -// A dummy Stream implementation for examples that require -// a Stream type but don't actually use it. -pub struct ResponseStream(T); - -impl Stream for ResponseStream { - type Item = T; - - fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { - unimplemented!() - } -} diff --git a/tonic-examples/src/load_balance/server.rs b/tonic-examples/src/load_balance/server.rs index 0c07b211d..67e5d108f 100644 --- a/tonic-examples/src/load_balance/server.rs +++ b/tonic-examples/src/load_balance/server.rs @@ -2,14 +2,16 @@ pub mod pb { tonic::include_proto!("grpc.examples.echo"); } -use pb::{EchoRequest, EchoResponse}; +use futures::Stream; use std::net::SocketAddr; +use std::pin::Pin; use tokio::sync::mpsc; use tonic::{transport::Server, Request, Response, Status, Streaming}; -use tonic_examples::ResponseStream; + +use pb::{EchoRequest, EchoResponse}; type EchoResult = Result, Status>; -type Stream = ResponseStream>; +type ResponseStream = Pin> + Send + Sync>>; #[derive(Debug)] pub struct EchoServer { @@ -24,7 +26,7 @@ impl pb::server::Echo for EchoServer { Ok(Response::new(EchoResponse { message })) } - type ServerStreamingEchoStream = Stream; + type ServerStreamingEchoStream = ResponseStream; async fn server_streaming_echo( &self, @@ -40,7 +42,7 @@ impl pb::server::Echo for EchoServer { Err(Status::unimplemented("not implemented")) } - type BidirectionalStreamingEchoStream = Stream; + type BidirectionalStreamingEchoStream = ResponseStream; async fn bidirectional_streaming_echo( &self, diff --git a/tonic-examples/src/multiplex/server.rs b/tonic-examples/src/multiplex/server.rs index e87c0ec7c..526b88702 100644 --- a/tonic-examples/src/multiplex/server.rs +++ b/tonic-examples/src/multiplex/server.rs @@ -1,5 +1,6 @@ +use futures::Stream; +use std::pin::Pin; use tonic::{transport::Server, Request, Response, Status}; -use tonic_examples::ResponseStream; pub mod hello_world { tonic::include_proto!("helloworld"); @@ -19,6 +20,8 @@ use echo::{ EchoRequest, EchoResponse, }; +type ResponseStream = Pin> + Send + Sync>>; + #[tokio::main] async fn main() -> Result<(), Box> { let addr = "[::1]:50051".parse().unwrap(); @@ -64,6 +67,6 @@ impl Echo for MyEcho { Ok(Response::new(EchoResponse { message })) } - type ServerStreamingEchoStream = ResponseStream>; - type BidirectionalStreamingEchoStream = ResponseStream>; + type ServerStreamingEchoStream = ResponseStream; + type BidirectionalStreamingEchoStream = ResponseStream; } diff --git a/tonic-examples/src/tls/server.rs b/tonic-examples/src/tls/server.rs index 7e27f5bdc..2aceca646 100644 --- a/tonic-examples/src/tls/server.rs +++ b/tonic-examples/src/tls/server.rs @@ -2,15 +2,16 @@ pub mod pb { tonic::include_proto!("/grpc.examples.echo"); } +use futures::Stream; use pb::{EchoRequest, EchoResponse}; +use std::pin::Pin; use tonic::{ transport::{Identity, Server, ServerTlsConfig}, Request, Response, Status, Streaming, }; -use tonic_examples::ResponseStream; type EchoResult = Result, Status>; -type Stream = ResponseStream>; +type ResponseStream = Pin> + Send + Sync>>; #[derive(Default)] pub struct EchoServer; @@ -22,7 +23,7 @@ impl pb::server::Echo for EchoServer { Ok(Response::new(EchoResponse { message })) } - type ServerStreamingEchoStream = Stream; + type ServerStreamingEchoStream = ResponseStream; async fn server_streaming_echo( &self, @@ -38,7 +39,7 @@ impl pb::server::Echo for EchoServer { Err(Status::unimplemented("not implemented")) } - type BidirectionalStreamingEchoStream = Stream; + type BidirectionalStreamingEchoStream = ResponseStream; async fn bidirectional_streaming_echo( &self, diff --git a/tonic-examples/src/tls_client_auth/server.rs b/tonic-examples/src/tls_client_auth/server.rs index 7491eb3c7..f987c741d 100644 --- a/tonic-examples/src/tls_client_auth/server.rs +++ b/tonic-examples/src/tls_client_auth/server.rs @@ -2,13 +2,14 @@ pub mod pb { tonic::include_proto!("grpc.examples.echo"); } +use futures::Stream; use pb::{EchoRequest, EchoResponse}; +use std::pin::Pin; use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig}; use tonic::{Request, Response, Status}; -use tonic_examples::ResponseStream; type EchoResult = Result, Status>; -type Stream = ResponseStream>; +type ResponseStream = Pin> + Send + Sync>>; #[derive(Default)] pub struct EchoServer; @@ -20,8 +21,8 @@ impl pb::server::Echo for EchoServer { Ok(Response::new(EchoResponse { message })) } - type ServerStreamingEchoStream = Stream; - type BidirectionalStreamingEchoStream = Stream; + type ServerStreamingEchoStream = ResponseStream; + type BidirectionalStreamingEchoStream = ResponseStream; } #[tokio::main]