fix(examples): Remove use of VecDeque as a placeholder type (#143)

This commit is contained in:
Juan Alvarez
2019-11-19 13:29:33 +00:00
committed by James Nugent
parent f9502dfd7e
commit 354d4fdc35
5 changed files with 29 additions and 21 deletions
+5 -4
View File
@@ -2,13 +2,14 @@ pub mod pb {
tonic::include_proto!("grpc.examples.echo"); tonic::include_proto!("grpc.examples.echo");
} }
use futures::Stream;
use pb::{EchoRequest, EchoResponse}; use pb::{EchoRequest, EchoResponse};
use std::collections::VecDeque; use std::pin::Pin;
use tonic::{body::BoxBody, transport::Server, Request, Response, Status, Streaming}; use tonic::{body::BoxBody, transport::Server, Request, Response, Status, Streaming};
use tower::Service; use tower::Service;
type EchoResult<T> = Result<Response<T>, Status>; type EchoResult<T> = Result<Response<T>, Status>;
type Stream = VecDeque<Result<EchoResponse, Status>>; type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send + Sync>>;
#[derive(Default)] #[derive(Default)]
pub struct EchoServer; pub struct EchoServer;
@@ -20,7 +21,7 @@ impl pb::server::Echo for EchoServer {
Ok(Response::new(EchoResponse { message })) Ok(Response::new(EchoResponse { message }))
} }
type ServerStreamingEchoStream = Stream; type ServerStreamingEchoStream = ResponseStream;
async fn server_streaming_echo( async fn server_streaming_echo(
&self, &self,
@@ -36,7 +37,7 @@ impl pb::server::Echo for EchoServer {
Err(Status::unimplemented("not implemented")) Err(Status::unimplemented("not implemented"))
} }
type BidirectionalStreamingEchoStream = Stream; type BidirectionalStreamingEchoStream = ResponseStream;
async fn bidirectional_streaming_echo( async fn bidirectional_streaming_echo(
&self, &self,
+8 -5
View File
@@ -2,13 +2,16 @@ pub mod pb {
tonic::include_proto!("grpc.examples.echo"); tonic::include_proto!("grpc.examples.echo");
} }
use pb::{EchoRequest, EchoResponse}; use futures::Stream;
use std::{collections::VecDeque, net::SocketAddr}; use std::net::SocketAddr;
use std::pin::Pin;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tonic::{transport::Server, Request, Response, Status, Streaming}; use tonic::{transport::Server, Request, Response, Status, Streaming};
use pb::{EchoRequest, EchoResponse};
type EchoResult<T> = Result<Response<T>, Status>; type EchoResult<T> = Result<Response<T>, Status>;
type Stream = VecDeque<Result<EchoResponse, Status>>; type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send + Sync>>;
#[derive(Debug)] #[derive(Debug)]
pub struct EchoServer { pub struct EchoServer {
@@ -23,7 +26,7 @@ impl pb::server::Echo for EchoServer {
Ok(Response::new(EchoResponse { message })) Ok(Response::new(EchoResponse { message }))
} }
type ServerStreamingEchoStream = Stream; type ServerStreamingEchoStream = ResponseStream;
async fn server_streaming_echo( async fn server_streaming_echo(
&self, &self,
@@ -39,7 +42,7 @@ impl pb::server::Echo for EchoServer {
Err(Status::unimplemented("not implemented")) Err(Status::unimplemented("not implemented"))
} }
type BidirectionalStreamingEchoStream = Stream; type BidirectionalStreamingEchoStream = ResponseStream;
async fn bidirectional_streaming_echo( async fn bidirectional_streaming_echo(
&self, &self,
+6 -3
View File
@@ -1,4 +1,5 @@
use std::collections::VecDeque; use futures::Stream;
use std::pin::Pin;
use tonic::{transport::Server, Request, Response, Status}; use tonic::{transport::Server, Request, Response, Status};
pub mod hello_world { pub mod hello_world {
@@ -19,6 +20,8 @@ use echo::{
EchoRequest, EchoResponse, EchoRequest, EchoResponse,
}; };
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send + Sync>>;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse().unwrap(); let addr = "[::1]:50051".parse().unwrap();
@@ -64,6 +67,6 @@ impl Echo for MyEcho {
Ok(Response::new(EchoResponse { message })) Ok(Response::new(EchoResponse { message }))
} }
type ServerStreamingEchoStream = VecDeque<Result<EchoResponse, Status>>; type ServerStreamingEchoStream = ResponseStream;
type BidirectionalStreamingEchoStream = VecDeque<Result<EchoResponse, Status>>; type BidirectionalStreamingEchoStream = ResponseStream;
} }
+5 -4
View File
@@ -2,15 +2,16 @@ pub mod pb {
tonic::include_proto!("/grpc.examples.echo"); tonic::include_proto!("/grpc.examples.echo");
} }
use futures::Stream;
use pb::{EchoRequest, EchoResponse}; use pb::{EchoRequest, EchoResponse};
use std::collections::VecDeque; use std::pin::Pin;
use tonic::{ use tonic::{
transport::{Identity, Server, ServerTlsConfig}, transport::{Identity, Server, ServerTlsConfig},
Request, Response, Status, Streaming, Request, Response, Status, Streaming,
}; };
type EchoResult<T> = Result<Response<T>, Status>; type EchoResult<T> = Result<Response<T>, Status>;
type Stream = VecDeque<Result<EchoResponse, Status>>; type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send + Sync>>;
#[derive(Default)] #[derive(Default)]
pub struct EchoServer; pub struct EchoServer;
@@ -22,7 +23,7 @@ impl pb::server::Echo for EchoServer {
Ok(Response::new(EchoResponse { message })) Ok(Response::new(EchoResponse { message }))
} }
type ServerStreamingEchoStream = Stream; type ServerStreamingEchoStream = ResponseStream;
async fn server_streaming_echo( async fn server_streaming_echo(
&self, &self,
@@ -38,7 +39,7 @@ impl pb::server::Echo for EchoServer {
Err(Status::unimplemented("not implemented")) Err(Status::unimplemented("not implemented"))
} }
type BidirectionalStreamingEchoStream = Stream; type BidirectionalStreamingEchoStream = ResponseStream;
async fn bidirectional_streaming_echo( async fn bidirectional_streaming_echo(
&self, &self,
+5 -5
View File
@@ -2,14 +2,14 @@ pub mod pb {
tonic::include_proto!("grpc.examples.echo"); tonic::include_proto!("grpc.examples.echo");
} }
use std::collections::VecDeque; use futures::Stream;
use pb::{EchoRequest, EchoResponse}; use pb::{EchoRequest, EchoResponse};
use std::pin::Pin;
use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig}; use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig};
use tonic::{Request, Response, Status}; use tonic::{Request, Response, Status};
type EchoResult<T> = Result<Response<T>, Status>; type EchoResult<T> = Result<Response<T>, Status>;
type Stream = VecDeque<Result<EchoResponse, Status>>; type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send + Sync>>;
#[derive(Default)] #[derive(Default)]
pub struct EchoServer; pub struct EchoServer;
@@ -21,8 +21,8 @@ impl pb::server::Echo for EchoServer {
Ok(Response::new(EchoResponse { message })) Ok(Response::new(EchoResponse { message }))
} }
type ServerStreamingEchoStream = Stream; type ServerStreamingEchoStream = ResponseStream;
type BidirectionalStreamingEchoStream = Stream; type BidirectionalStreamingEchoStream = ResponseStream;
} }
#[tokio::main] #[tokio::main]