diff --git a/Cargo.toml b/Cargo.toml index 7687b5d..bbcce3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,5 +3,5 @@ members = [ "tonic", "tonic-build", "tonic-examples", - # "tonic-interop", + "tonic-interop", ] diff --git a/tonic-examples/src/routeguide/server.rs b/tonic-examples/src/routeguide/server.rs index 74e181b..cb657e7 100644 --- a/tonic-examples/src/routeguide/server.rs +++ b/tonic-examples/src/routeguide/server.rs @@ -3,12 +3,12 @@ mod data; use futures::{Stream, StreamExt}; use std::collections::HashMap; use std::hash::{Hash, Hasher}; +use std::pin::Pin; use std::sync::Arc; use std::time::Instant; use tokio::sync::{mpsc, Lock}; use tonic::transport::Server; use tonic::{Request, Response, Status}; -use std::pin::Pin; pub mod routeguide { include!(concat!(env!("OUT_DIR"), "/routeguide.rs")); @@ -147,7 +147,10 @@ impl routeguide::RouteGuide for RouteGuide { }; // TODO: Clean this up - Ok(Response::new(Box::pin(output) as Pin> + Send + 'static>>)) + Ok(Response::new(Box::pin(output) + as Pin< + Box> + Send + 'static>, + >)) } } @@ -167,9 +170,7 @@ async fn main() -> Result<(), Box> { let svc = routeguide::RouteGuideServer::new(route_guide); - Server::builder() - .serve(addr, svc) - .await?; + Server::builder().serve(addr, svc).await?; Ok(()) } diff --git a/tonic-interop/Cargo.toml b/tonic-interop/Cargo.toml index 0e9a1ac..822436a 100644 --- a/tonic-interop/Cargo.toml +++ b/tonic-interop/Cargo.toml @@ -19,6 +19,7 @@ prost = "0.5" prost-derive = "0.5" bytes = "0.4" http = "0.1" +futures-core-preview = "=0.3.0-alpha.18" futures-util-preview = "=0.3.0-alpha.18" console = "0.7" diff --git a/tonic-interop/build.rs b/tonic-interop/build.rs index 5166d97..9ec7f5d 100644 --- a/tonic-interop/build.rs +++ b/tonic-interop/build.rs @@ -2,7 +2,7 @@ fn main() { let files = &["proto/grpc/testing/test.proto"]; let dirs = &["proto/grpc/testing"]; - tonic_build::compile_protos(files, dirs).unwrap(); + tonic_build::compile_protos(files, dirs, "grpc.testing").unwrap(); // prevent needing to rebuild if files (or deps) haven't changed for file in files { diff --git a/tonic-interop/src/bin/server.rs b/tonic-interop/src/bin/server.rs index c03a3b0..9acfa22 100644 --- a/tonic-interop/src/bin/server.rs +++ b/tonic-interop/src/bin/server.rs @@ -1,12 +1,11 @@ use structopt::StructOpt; -use tonic::transport::Server; -use tonic::{Code, Request, Response, Status}; +use tonic::{Code, Request, Response, Status, Server}; +use std::pin::Pin; pub mod pb { #![allow(dead_code)] #![allow(unused_imports)] include!(concat!(env!("OUT_DIR"), "/grpc.testing.rs")); - tonic::client!(service = "grpc.testing.TestService", proto = "self"); } use pb::*; @@ -16,17 +15,21 @@ pub struct TestService { data: String, } -#[tonic::server(service = "grpc.testing.TestService", proto = "pb")] -impl TestService { - pub async fn empty_call(&self, _request: Request) -> Result, Status> { +type Result = std::result::Result, Status>; +type Streaming = Request>; +type Stream = Pin> + Send + 'static>>; + +#[tonic::async_trait] +impl pb::TestService for TestService { + async fn empty_call(&self, _request: Request) -> Result { println!("empty_call"); Ok(Response::new(Empty {})) } - pub async fn unary_call( + async fn unary_call( &self, request: Request, - ) -> Result, Status> { + ) -> Result { println!("unary_call"); let req = request.into_inner(); @@ -53,6 +56,36 @@ impl TestService { Ok(Response::new(res)) } + + async fn cacheable_unary_call(&self, _: Request) -> Result { + unimplemented!() + } + + type StreamingOutputCallStream = Stream; + + async fn streaming_output_call(&self, _: Request) -> Result { + unimplemented!() + } + + async fn streaming_input_call(&self, _: Streaming) -> Result { + unimplemented!() + } + + type FullDuplexCallStream = Stream; + + async fn full_duplex_call(&self, _: Streaming) -> Result { + unimplemented!() + } + + type HalfDuplexCallStream = Stream; + + async fn half_duplex_call(&self, _: Streaming) -> Result { + unimplemented!() + } + + async fn unimplemented_call(&self, _: Request) -> Result { + unimplemented!() + } } #[derive(StructOpt)] @@ -62,7 +95,7 @@ struct Opts { } #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> std::result::Result<(), Box> { let matches = Opts::from_args(); pretty_env_logger::init(); diff --git a/tonic-interop/src/client.rs b/tonic-interop/src/client.rs index d0093ee..b2e1204 100644 --- a/tonic-interop/src/client.rs +++ b/tonic-interop/src/client.rs @@ -7,12 +7,6 @@ use tonic::{metadata::MetadataValue, Code, Request, Response, Status}; pub type TestClient = TestServiceClient; pub type UnimplementedClient = UnimplementedServiceClient; -tonic::client!(service = "grpc.testing.TestService", proto = "crate::pb"); -tonic::client!( - service = "grpc.testing.UnimplementedService", - proto = "crate::pb" -); - const LARGE_REQ_SIZE: usize = 271828; const LARGE_RSP_SIZE: i32 = 314159; const REQUEST_LENGTHS: &'static [i32] = &[27182, 8, 1828, 45904];