Skip to content

Commit

Permalink
fix(examples): Remove use of VecDeque as a placeholder type (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
alce authored and jen20 committed Nov 19, 2019
1 parent f9502df commit 354d4fd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
9 changes: 5 additions & 4 deletions tonic-examples/src/authentication/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)]
pub struct EchoServer;
Expand All @@ -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,
Expand All @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions tonic-examples/src/load_balance/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)]
pub struct EchoServer {
Expand All @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions tonic-examples/src/multiplex/server.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -19,6 +20,8 @@ use echo::{
EchoRequest, EchoResponse,
};

type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send + Sync>>;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse().unwrap();
Expand Down Expand Up @@ -64,6 +67,6 @@ impl Echo for MyEcho {
Ok(Response::new(EchoResponse { message }))
}

type ServerStreamingEchoStream = VecDeque<Result<EchoResponse, Status>>;
type BidirectionalStreamingEchoStream = VecDeque<Result<EchoResponse, Status>>;
type ServerStreamingEchoStream = ResponseStream;
type BidirectionalStreamingEchoStream = ResponseStream;
}
9 changes: 5 additions & 4 deletions tonic-examples/src/tls/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)]
pub struct EchoServer;
Expand All @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions tonic-examples/src/tls_client_auth/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)]
pub struct EchoServer;
Expand All @@ -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]
Expand Down

0 comments on commit 354d4fd

Please sign in to comment.