diff --git a/tonic-examples/src/authentication/server.rs b/tonic-examples/src/authentication/server.rs index cf49da0c0..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::collections::VecDeque; +use std::pin::Pin; use tonic::{body::BoxBody, transport::Server, Request, Response, Status, Streaming}; use tower::Service; type EchoResult = Result, Status>; -type Stream = VecDeque>; +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/load_balance/server.rs b/tonic-examples/src/load_balance/server.rs index ee68be498..67e5d108f 100644 --- a/tonic-examples/src/load_balance/server.rs +++ b/tonic-examples/src/load_balance/server.rs @@ -2,13 +2,16 @@ pub mod pb { tonic::include_proto!("grpc.examples.echo"); } -use pb::{EchoRequest, EchoResponse}; -use std::{collections::VecDeque, net::SocketAddr}; +use futures::Stream; +use std::net::SocketAddr; +use std::pin::Pin; use tokio::sync::mpsc; use tonic::{transport::Server, Request, Response, Status, Streaming}; +use pb::{EchoRequest, EchoResponse}; + type EchoResult = Result, Status>; -type Stream = VecDeque>; +type ResponseStream = Pin> + Send + Sync>>; #[derive(Debug)] pub struct EchoServer { @@ -23,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, @@ -39,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 a8af6e4af..526b88702 100644 --- a/tonic-examples/src/multiplex/server.rs +++ b/tonic-examples/src/multiplex/server.rs @@ -1,4 +1,5 @@ -use std::collections::VecDeque; +use futures::Stream; +use std::pin::Pin; use tonic::{transport::Server, Request, Response, Status}; pub mod hello_world { @@ -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 = 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..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::collections::VecDeque; +use std::pin::Pin; use tonic::{ transport::{Identity, Server, ServerTlsConfig}, Request, Response, Status, Streaming, }; type EchoResult = Result, Status>; -type Stream = VecDeque>; +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 7ee7f2dd0..f987c741d 100644 --- a/tonic-examples/src/tls_client_auth/server.rs +++ b/tonic-examples/src/tls_client_auth/server.rs @@ -2,14 +2,14 @@ pub mod pb { tonic::include_proto!("grpc.examples.echo"); } -use std::collections::VecDeque; - +use futures::Stream; use pb::{EchoRequest, EchoResponse}; +use std::pin::Pin; use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig}; use tonic::{Request, Response, Status}; type EchoResult = Result, Status>; -type Stream = VecDeque>; +type ResponseStream = Pin> + Send + Sync>>; #[derive(Default)] pub struct EchoServer; @@ -21,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]