Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove VecDeque from examples #143

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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