diff --git a/examples/helloworld-tutorial.md b/examples/helloworld-tutorial.md index b2d6e65fc..7a349bc78 100644 --- a/examples/helloworld-tutorial.md +++ b/examples/helloworld-tutorial.md @@ -158,7 +158,6 @@ Next up, let's implement the Greeter service we previously defined in our `.prot #[derive(Debug, Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, @@ -207,7 +206,6 @@ pub mod hello_world { #[derive(Debug, Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/routeguide-tutorial.md b/examples/routeguide-tutorial.md index 88ae833af..8aee769b2 100644 --- a/examples/routeguide-tutorial.md +++ b/examples/routeguide-tutorial.md @@ -269,7 +269,6 @@ use tokio_stream::{wrappers::ReceiverStream, Stream}; ``` ```rust -#[tonic::async_trait] impl RouteGuide for RouteGuideService { async fn get_feature(&self, _request: Request) -> Result, Status> { unimplemented!() @@ -302,13 +301,8 @@ impl RouteGuide for RouteGuideService { } ``` -**Note**: The `tonic::async_trait` attribute macro adds support for async functions in traits. It -uses [async-trait] internally. You can learn more about `async fn` in traits in the [async book]. - [cargo book]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts -[async-trait]: https://github.com/dtolnay/async-trait -[async book]: https://rust-lang.github.io/async-book/07_workarounds/05_async_in_traits.html ### Server state Our service needs access to an immutable list of features. When the server starts, we are going to diff --git a/examples/src/authentication/server.rs b/examples/src/authentication/server.rs index d0a59cbc1..907683d58 100644 --- a/examples/src/authentication/server.rs +++ b/examples/src/authentication/server.rs @@ -10,7 +10,6 @@ type EchoResult = Result, Status>; #[derive(Default)] pub struct EchoServer; -#[tonic::async_trait] impl pb::echo_server::Echo for EchoServer { async fn unary_echo(&self, request: Request) -> EchoResult { let message = request.into_inner().message; diff --git a/examples/src/autoreload/server.rs b/examples/src/autoreload/server.rs index a181f75ec..05582bb72 100644 --- a/examples/src/autoreload/server.rs +++ b/examples/src/autoreload/server.rs @@ -10,7 +10,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/blocking/server.rs b/examples/src/blocking/server.rs index d7ef6177b..6a7b89ced 100644 --- a/examples/src/blocking/server.rs +++ b/examples/src/blocking/server.rs @@ -12,7 +12,6 @@ pub mod hello_world { #[derive(Debug, Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/cancellation/server.rs b/examples/src/cancellation/server.rs index 32d93e7d7..f83fa289c 100644 --- a/examples/src/cancellation/server.rs +++ b/examples/src/cancellation/server.rs @@ -17,7 +17,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/compression/server.rs b/examples/src/compression/server.rs index fd035d218..1f20c4416 100644 --- a/examples/src/compression/server.rs +++ b/examples/src/compression/server.rs @@ -11,7 +11,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/dynamic/server.rs b/examples/src/dynamic/server.rs index 300ec868c..27abe4386 100644 --- a/examples/src/dynamic/server.rs +++ b/examples/src/dynamic/server.rs @@ -20,7 +20,6 @@ type EchoResult = Result, Status>; #[derive(Default)] pub struct MyEcho {} -#[tonic::async_trait] impl Echo for MyEcho { async fn unary_echo(&self, request: Request) -> EchoResult { println!("Got an echo request from {:?}", request.remote_addr()); @@ -43,7 +42,6 @@ fn init_echo(args: &[String], builder: &mut RoutesBuilder) { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/dynamic_load_balance/server.rs b/examples/src/dynamic_load_balance/server.rs index 7935e1cf5..b2f345b8c 100644 --- a/examples/src/dynamic_load_balance/server.rs +++ b/examples/src/dynamic_load_balance/server.rs @@ -15,7 +15,6 @@ pub struct EchoServer { addr: SocketAddr, } -#[tonic::async_trait] impl pb::echo_server::Echo for EchoServer { async fn unary_echo(&self, request: Request) -> EchoResult { let message = format!("{} (from {})", request.into_inner().message, self.addr); diff --git a/examples/src/grpc-web/server.rs b/examples/src/grpc-web/server.rs index 7734a7663..3770acad1 100644 --- a/examples/src/grpc-web/server.rs +++ b/examples/src/grpc-web/server.rs @@ -10,7 +10,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/h2c/server.rs b/examples/src/h2c/server.rs index 92d08a417..20d84138c 100644 --- a/examples/src/h2c/server.rs +++ b/examples/src/h2c/server.rs @@ -11,7 +11,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/health/server.rs b/examples/src/health/server.rs index 7b12e8668..2b3a9a7a3 100644 --- a/examples/src/health/server.rs +++ b/examples/src/health/server.rs @@ -12,7 +12,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/helloworld/server.rs b/examples/src/helloworld/server.rs index c6398bb61..90de9f34c 100644 --- a/examples/src/helloworld/server.rs +++ b/examples/src/helloworld/server.rs @@ -10,7 +10,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/hyper_warp/server.rs b/examples/src/hyper_warp/server.rs index a79caf401..5a021db27 100644 --- a/examples/src/hyper_warp/server.rs +++ b/examples/src/hyper_warp/server.rs @@ -27,7 +27,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/hyper_warp_multiplex/server.rs b/examples/src/hyper_warp_multiplex/server.rs index deea8bea5..bbf80674c 100644 --- a/examples/src/hyper_warp_multiplex/server.rs +++ b/examples/src/hyper_warp_multiplex/server.rs @@ -37,7 +37,6 @@ use echo::{ #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, @@ -53,7 +52,6 @@ impl Greeter for MyGreeter { #[derive(Default)] pub struct MyEcho; -#[tonic::async_trait] impl Echo for MyEcho { async fn unary_echo( &self, diff --git a/examples/src/interceptor/server.rs b/examples/src/interceptor/server.rs index 263348a6d..c90490591 100644 --- a/examples/src/interceptor/server.rs +++ b/examples/src/interceptor/server.rs @@ -10,7 +10,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/json-codec/server.rs b/examples/src/json-codec/server.rs index 1029b0bf9..2c2b00c54 100644 --- a/examples/src/json-codec/server.rs +++ b/examples/src/json-codec/server.rs @@ -17,7 +17,6 @@ use hello_world::greeter_server::{Greeter, GreeterServer}; #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/load_balance/server.rs b/examples/src/load_balance/server.rs index 7935e1cf5..b2f345b8c 100644 --- a/examples/src/load_balance/server.rs +++ b/examples/src/load_balance/server.rs @@ -15,7 +15,6 @@ pub struct EchoServer { addr: SocketAddr, } -#[tonic::async_trait] impl pb::echo_server::Echo for EchoServer { async fn unary_echo(&self, request: Request) -> EchoResult { let message = format!("{} (from {})", request.into_inner().message, self.addr); diff --git a/examples/src/mock/mock.rs b/examples/src/mock/mock.rs index 0d3754921..0c9d2ac9d 100644 --- a/examples/src/mock/mock.rs +++ b/examples/src/mock/mock.rs @@ -63,7 +63,6 @@ async fn main() -> Result<(), Box> { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/multiplex/server.rs b/examples/src/multiplex/server.rs index 9b148c861..e5613cf55 100644 --- a/examples/src/multiplex/server.rs +++ b/examples/src/multiplex/server.rs @@ -37,7 +37,6 @@ async fn main() -> Result<(), Box> { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, @@ -53,7 +52,6 @@ impl Greeter for MyGreeter { #[derive(Default)] pub struct MyEcho; -#[tonic::async_trait] impl Echo for MyEcho { async fn unary_echo( &self, diff --git a/examples/src/optional/server.rs b/examples/src/optional/server.rs index f1d4fa685..5bba5000b 100644 --- a/examples/src/optional/server.rs +++ b/examples/src/optional/server.rs @@ -11,7 +11,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/reflection/server.rs b/examples/src/reflection/server.rs index 500141fbb..5dc6d6f85 100644 --- a/examples/src/reflection/server.rs +++ b/examples/src/reflection/server.rs @@ -11,7 +11,6 @@ mod proto { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl proto::greeter_server::Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/richer-error/server.rs b/examples/src/richer-error/server.rs index cb1e6cf38..c178bad51 100644 --- a/examples/src/richer-error/server.rs +++ b/examples/src/richer-error/server.rs @@ -11,7 +11,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/richer-error/server_vec.rs b/examples/src/richer-error/server_vec.rs index 8ecf2e45c..c2cb58bf1 100644 --- a/examples/src/richer-error/server_vec.rs +++ b/examples/src/richer-error/server_vec.rs @@ -11,7 +11,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/routeguide/server.rs b/examples/src/routeguide/server.rs index c3ec4b32b..cdc41aaa6 100644 --- a/examples/src/routeguide/server.rs +++ b/examples/src/routeguide/server.rs @@ -22,7 +22,6 @@ pub struct RouteGuideService { features: Arc>, } -#[tonic::async_trait] impl RouteGuide for RouteGuideService { async fn get_feature(&self, request: Request) -> Result, Status> { println!("GetFeature = {:?}", request); diff --git a/examples/src/streaming/server.rs b/examples/src/streaming/server.rs index 34d03fa0c..65f019f95 100644 --- a/examples/src/streaming/server.rs +++ b/examples/src/streaming/server.rs @@ -38,7 +38,6 @@ fn match_for_io_error(err_status: &Status) -> Option<&std::io::Error> { #[derive(Debug)] pub struct EchoServer {} -#[tonic::async_trait] impl pb::echo_server::Echo for EchoServer { async fn unary_echo(&self, _: Request) -> EchoResult { Err(Status::unimplemented("not implemented")) diff --git a/examples/src/timeout/server.rs b/examples/src/timeout/server.rs index 2d5b1fa2e..7b26a0b8f 100644 --- a/examples/src/timeout/server.rs +++ b/examples/src/timeout/server.rs @@ -12,7 +12,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/tls/server.rs b/examples/src/tls/server.rs index 08697b221..149228d90 100644 --- a/examples/src/tls/server.rs +++ b/examples/src/tls/server.rs @@ -16,7 +16,6 @@ type EchoResult = Result, Status>; #[derive(Default)] pub struct EchoServer; -#[tonic::async_trait] impl pb::echo_server::Echo for EchoServer { async fn unary_echo(&self, request: Request) -> EchoResult { let conn_info = request diff --git a/examples/src/tls_client_auth/server.rs b/examples/src/tls_client_auth/server.rs index 840c70ac9..b1b5f841f 100644 --- a/examples/src/tls_client_auth/server.rs +++ b/examples/src/tls_client_auth/server.rs @@ -11,7 +11,6 @@ type EchoResult = Result, Status>; #[derive(Default)] pub struct EchoServer; -#[tonic::async_trait] impl pb::echo_server::Echo for EchoServer { async fn unary_echo(&self, request: Request) -> EchoResult { let certs = request diff --git a/examples/src/tls_rustls/server.rs b/examples/src/tls_rustls/server.rs index 82f009344..0f39db02f 100644 --- a/examples/src/tls_rustls/server.rs +++ b/examples/src/tls_rustls/server.rs @@ -102,7 +102,6 @@ type EchoResult = Result, Status>; #[derive(Default)] pub struct EchoServer; -#[tonic::async_trait] impl pb::echo_server::Echo for EchoServer { async fn unary_echo(&self, request: Request) -> EchoResult { let conn_info = request.extensions().get::>().unwrap(); diff --git a/examples/src/tower/server.rs b/examples/src/tower/server.rs index cc85d62e5..be8cde140 100644 --- a/examples/src/tower/server.rs +++ b/examples/src/tower/server.rs @@ -17,7 +17,6 @@ pub mod hello_world { #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/examples/src/tracing/server.rs b/examples/src/tracing/server.rs index a068219a8..9fc9adf48 100644 --- a/examples/src/tracing/server.rs +++ b/examples/src/tracing/server.rs @@ -12,7 +12,6 @@ use hello_world::{ #[derive(Debug, Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { #[tracing::instrument] async fn say_hello( diff --git a/examples/src/uds/server.rs b/examples/src/uds/server.rs index ccf9c91a8..db6056d43 100644 --- a/examples/src/uds/server.rs +++ b/examples/src/uds/server.rs @@ -21,7 +21,6 @@ use hello_world::{ #[derive(Default)] pub struct MyGreeter {} -#[tonic::async_trait] impl Greeter for MyGreeter { async fn say_hello( &self, diff --git a/interop/src/server.rs b/interop/src/server.rs index 6ffb16309..8a472756f 100644 --- a/interop/src/server.rs +++ b/interop/src/server.rs @@ -22,7 +22,6 @@ type Stream = Pin> + Send + 'static>>; type BoxFuture = Pin> + Send + 'static>>; -#[tonic::async_trait] impl pb::test_service_server::TestService for TestService { async fn empty_call(&self, _request: Request) -> Result { Ok(Response::new(Empty {})) @@ -158,7 +157,6 @@ impl pb::test_service_server::TestService for TestService { #[derive(Default)] pub struct UnimplementedService; -#[tonic::async_trait] impl pb::unimplemented_service_server::UnimplementedService for UnimplementedService { async fn unimplemented_call(&self, _req: Request) -> Result { Err(Status::unimplemented("")) diff --git a/tests/ambiguous_methods/src/main.rs b/tests/ambiguous_methods/src/main.rs index b8673be27..b0cce8e66 100644 --- a/tests/ambiguous_methods/src/main.rs +++ b/tests/ambiguous_methods/src/main.rs @@ -1,6 +1,3 @@ -#[macro_use] -extern crate tonic; - tonic::include_proto!("ambiguous_methods"); fn main() { diff --git a/tests/compression/src/lib.rs b/tests/compression/src/lib.rs index 02f729b60..6837f9269 100644 --- a/tests/compression/src/lib.rs +++ b/tests/compression/src/lib.rs @@ -44,7 +44,6 @@ impl Svc { } } -#[tonic::async_trait] impl test_server::Test for Svc { async fn compress_output_unary(&self, _req: Request<()>) -> Result, Status> { let data = [0_u8; UNCOMPRESSED_MIN_BODY_SIZE]; diff --git a/tests/default_stubs/src/lib.rs b/tests/default_stubs/src/lib.rs index bbf98d4ae..accb1b83e 100644 --- a/tests/default_stubs/src/lib.rs +++ b/tests/default_stubs/src/lib.rs @@ -12,7 +12,6 @@ tonic::include_proto!("test_default"); #[derive(Debug, Default)] struct Svc; -#[tonic::async_trait] impl test_server::Test for Svc { type ServerStreamStream = Pin> + Send + 'static>>; type BidirectionalStreamStream = @@ -41,7 +40,6 @@ impl test_server::Test for Svc { } } -#[tonic::async_trait] impl test_default_server::TestDefault for Svc { // Default unimplemented stubs provided here. } diff --git a/tests/integration_tests/tests/client_layer.rs b/tests/integration_tests/tests/client_layer.rs index 01fa5c17f..563bb42f0 100644 --- a/tests/integration_tests/tests/client_layer.rs +++ b/tests/integration_tests/tests/client_layer.rs @@ -13,7 +13,6 @@ use tower_http::{set_header::SetRequestHeaderLayer, trace::TraceLayer}; async fn connect_supports_standard_tower_layers() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, req: Request) -> Result, Status> { match req.metadata().get("x-test") { diff --git a/tests/integration_tests/tests/complex_tower_middleware.rs b/tests/integration_tests/tests/complex_tower_middleware.rs index 5d7690be3..ea35e089b 100644 --- a/tests/integration_tests/tests/complex_tower_middleware.rs +++ b/tests/integration_tests/tests/complex_tower_middleware.rs @@ -14,7 +14,6 @@ use tower::{layer::Layer, BoxError, Service}; async fn complex_tower_layers_work() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, req: Request) -> Result, Status> { unimplemented!() diff --git a/tests/integration_tests/tests/connect_info.rs b/tests/integration_tests/tests/connect_info.rs index 94fac8221..a356a55cc 100644 --- a/tests/integration_tests/tests/connect_info.rs +++ b/tests/integration_tests/tests/connect_info.rs @@ -10,7 +10,6 @@ use tonic::{ async fn getting_connect_info() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, req: Request) -> Result, Status> { assert!(req.local_addr().is_some()); @@ -66,7 +65,6 @@ pub mod unix { struct Svc {} - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, req: Request) -> Result, Status> { let conn_info = req.extensions().get::().unwrap(); diff --git a/tests/integration_tests/tests/connection.rs b/tests/integration_tests/tests/connection.rs index bb67adf55..e30ca8f64 100644 --- a/tests/integration_tests/tests/connection.rs +++ b/tests/integration_tests/tests/connection.rs @@ -9,7 +9,6 @@ use tonic::{ struct Svc(Arc>>>); -#[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, _: Request) -> Result, Status> { let mut l = self.0.lock().unwrap(); diff --git a/tests/integration_tests/tests/extensions.rs b/tests/integration_tests/tests/extensions.rs index b112f8e66..ada8aa0dd 100644 --- a/tests/integration_tests/tests/extensions.rs +++ b/tests/integration_tests/tests/extensions.rs @@ -22,7 +22,6 @@ struct ExtensionValue(i32); async fn setting_extension_from_interceptor() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, req: Request) -> Result, Status> { let value = req.extensions().get::().unwrap(); @@ -67,7 +66,6 @@ async fn setting_extension_from_interceptor() { async fn setting_extension_from_tower() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, req: Request) -> Result, Status> { let value = req.extensions().get::().unwrap(); diff --git a/tests/integration_tests/tests/interceptor.rs b/tests/integration_tests/tests/interceptor.rs index 23f2f25cf..2934a2909 100644 --- a/tests/integration_tests/tests/interceptor.rs +++ b/tests/integration_tests/tests/interceptor.rs @@ -12,7 +12,6 @@ async fn interceptor_retrieves_grpc_method() { struct Svc; - #[tonic::async_trait] impl Test for Svc { async fn unary_call(&self, _: Request) -> Result, Status> { Ok(Response::new(Output {})) diff --git a/tests/integration_tests/tests/max_message_size.rs b/tests/integration_tests/tests/max_message_size.rs index 9ae524dbc..37e3e02a0 100644 --- a/tests/integration_tests/tests/max_message_size.rs +++ b/tests/integration_tests/tests/max_message_size.rs @@ -121,7 +121,6 @@ async fn response_stream_limit() { struct Svc; - #[tonic::async_trait] impl test1_server::Test1 for Svc { async fn unary_call(&self, _req: Request) -> Result, Status> { unimplemented!() @@ -281,7 +280,6 @@ async fn max_message_run(case: &TestCase) -> Result<(), Status> { struct Svc(Vec); - #[tonic::async_trait] impl test1_server::Test1 for Svc { async fn unary_call(&self, _req: Request) -> Result, Status> { Ok(Response::new(Output1 { diff --git a/tests/integration_tests/tests/origin.rs b/tests/integration_tests/tests/origin.rs index f149dc68d..95c691989 100644 --- a/tests/integration_tests/tests/origin.rs +++ b/tests/integration_tests/tests/origin.rs @@ -17,7 +17,6 @@ use tower::Service; async fn writes_origin_header() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call( &self, diff --git a/tests/integration_tests/tests/routes_builder.rs b/tests/integration_tests/tests/routes_builder.rs index 7bcbfad37..d620acca5 100644 --- a/tests/integration_tests/tests/routes_builder.rs +++ b/tests/integration_tests/tests/routes_builder.rs @@ -17,7 +17,6 @@ use tonic::{ async fn multiple_service_using_routes_builder() { struct Svc1; - #[tonic::async_trait] impl test_server::Test for Svc1 { async fn unary_call(&self, _req: Request) -> Result, Status> { Ok(Response::new(Output {})) @@ -26,7 +25,6 @@ async fn multiple_service_using_routes_builder() { struct Svc2; - #[tonic::async_trait] impl test1_server::Test1 for Svc2 { async fn unary_call(&self, request: Request) -> Result, Status> { Ok(Response::new(Output1 { diff --git a/tests/integration_tests/tests/status.rs b/tests/integration_tests/tests/status.rs index 3fdabcd36..832600611 100644 --- a/tests/integration_tests/tests/status.rs +++ b/tests/integration_tests/tests/status.rs @@ -16,7 +16,6 @@ use tonic::{transport::Server, Code, Request, Response, Status}; async fn status_with_details() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, _: Request) -> Result, Status> { Err(Status::with_details( @@ -70,7 +69,6 @@ async fn status_with_metadata() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, _: Request) -> Result, Status> { let mut metadata = MetadataMap::new(); @@ -134,7 +132,6 @@ async fn status_from_server_stream() { struct Svc; - #[tonic::async_trait] impl test_stream_server::TestStream for Svc { type StreamCallStream = Stream; diff --git a/tests/integration_tests/tests/streams.rs b/tests/integration_tests/tests/streams.rs index 8ce2e93bf..8c0715aaa 100644 --- a/tests/integration_tests/tests/streams.rs +++ b/tests/integration_tests/tests/streams.rs @@ -10,7 +10,6 @@ type Stream = std::pin::Pin< async fn status_from_server_stream_with_source() { struct Svc; - #[tonic::async_trait] impl test_stream_server::TestStream for Svc { type StreamCallStream = Stream; diff --git a/tests/integration_tests/tests/timeout.rs b/tests/integration_tests/tests/timeout.rs index 450a67d21..075815984 100644 --- a/tests/integration_tests/tests/timeout.rs +++ b/tests/integration_tests/tests/timeout.rs @@ -66,7 +66,6 @@ async fn run_service_in_background(latency: Duration, server_timeout: Duration) latency: Duration, } - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, _req: Request) -> Result, Status> { tokio::time::sleep(self.latency).await; diff --git a/tests/integration_tests/tests/user_agent.rs b/tests/integration_tests/tests/user_agent.rs index 46747c97a..6715585d1 100644 --- a/tests/integration_tests/tests/user_agent.rs +++ b/tests/integration_tests/tests/user_agent.rs @@ -10,7 +10,6 @@ use tonic::{ async fn writes_user_agent_header() { struct Svc; - #[tonic::async_trait] impl test_server::Test for Svc { async fn unary_call(&self, req: Request) -> Result, Status> { match req.metadata().get("user-agent") { diff --git a/tests/use_arc_self/src/lib.rs b/tests/use_arc_self/src/lib.rs index 6b12b588e..82f70d08c 100644 --- a/tests/use_arc_self/src/lib.rs +++ b/tests/use_arc_self/src/lib.rs @@ -9,7 +9,6 @@ tonic::include_proto!("test"); #[derive(Debug, Default)] struct Svc; -#[tonic::async_trait] impl test_server::Test for Svc { async fn test_request( self: Arc, diff --git a/tonic-build/src/server.rs b/tonic-build/src/server.rs index d9ab1ad6b..7db636d3f 100644 --- a/tonic-build/src/server.rs +++ b/tonic-build/src/server.rs @@ -237,7 +237,6 @@ fn generate_trait( quote! { #trait_doc - #[async_trait] pub trait #server_trait : Send + Sync + 'static { #methods } @@ -282,41 +281,41 @@ fn generate_trait_methods( (false, false, true) => { quote! { #method_doc - async fn #name(#self_param, request: tonic::Request<#req_message>) - -> std::result::Result, tonic::Status> { - Err(tonic::Status::unimplemented("Not yet implemented")) + fn #name(#self_param, request: tonic::Request<#req_message>) + -> impl Future, tonic::Status>> + Send { + async { Err(tonic::Status::unimplemented("Not yet implemented")) } } } } (false, false, false) => { quote! { #method_doc - async fn #name(#self_param, request: tonic::Request<#req_message>) - -> std::result::Result, tonic::Status>; + fn #name(#self_param, request: tonic::Request<#req_message>) + -> impl Future, tonic::Status>> + Send; } } (true, false, true) => { quote! { #method_doc - async fn #name(#self_param, request: tonic::Request>) - -> std::result::Result, tonic::Status> { - Err(tonic::Status::unimplemented("Not yet implemented")) + fn #name(#self_param, request: tonic::Request>) + -> impl Future, tonic::Status>> + Send { + async { Err(tonic::Status::unimplemented("Not yet implemented")) } } } } (true, false, false) => { quote! { #method_doc - async fn #name(#self_param, request: tonic::Request>) - -> std::result::Result, tonic::Status>; + fn #name(#self_param, request: tonic::Request>) + -> impl Future, tonic::Status>> + Send; } } (false, true, true) => { quote! { #method_doc - async fn #name(#self_param, request: tonic::Request<#req_message>) - -> std::result::Result>, tonic::Status> { - Err(tonic::Status::unimplemented("Not yet implemented")) + fn #name(#self_param, request: tonic::Request<#req_message>) + -> impl Future>, tonic::Status>> + Send { + async { Err(tonic::Status::unimplemented("Not yet implemented")) } } } } @@ -332,16 +331,16 @@ fn generate_trait_methods( type #stream: tonic::codegen::tokio_stream::Stream> + Send + 'static; #method_doc - async fn #name(#self_param, request: tonic::Request<#req_message>) - -> std::result::Result, tonic::Status>; + fn #name(#self_param, request: tonic::Request<#req_message>) + -> impl Future, tonic::Status>> + Send; } } (true, true, true) => { quote! { #method_doc - async fn #name(#self_param, request: tonic::Request>) - -> std::result::Result>, tonic::Status> { - Err(tonic::Status::unimplemented("Not yet implemented")) + fn #name(#self_param, request: tonic::Request>) + -> impl Future>, tonic::Status>> + Send { + async { Err(tonic::Status::unimplemented("Not yet implemented")) } } } } @@ -357,8 +356,8 @@ fn generate_trait_methods( type #stream: tonic::codegen::tokio_stream::Stream> + Send + 'static; #method_doc - async fn #name(#self_param, request: tonic::Request>) - -> std::result::Result, tonic::Status>; + fn #name(#self_param, request: tonic::Request>) + -> impl Future, tonic::Status>> + Send; } } }; diff --git a/tonic-health/src/generated/grpc_health_v1.rs b/tonic-health/src/generated/grpc_health_v1.rs index 9662361f0..a694f94a4 100644 --- a/tonic-health/src/generated/grpc_health_v1.rs +++ b/tonic-health/src/generated/grpc_health_v1.rs @@ -204,17 +204,18 @@ pub mod health_server { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] use tonic::codegen::*; /// Generated trait containing gRPC methods that should be implemented for use with HealthServer. - #[async_trait] pub trait Health: Send + Sync + 'static { /// If the requested service is unknown, the call will fail with status /// NOT_FOUND. - async fn check( + fn check( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> impl Future< + Output = std::result::Result< + tonic::Response, + tonic::Status, + >, + > + Send; /// Server streaming response type for the Watch method. type WatchStream: tonic::codegen::tokio_stream::Stream< Item = std::result::Result, @@ -236,10 +237,15 @@ pub mod health_server { /// should assume this method is not supported and should not retry the /// call. If the call terminates with any other status (including OK), /// clients should retry the call with appropriate exponential backoff. - async fn watch( + fn watch( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status>; + ) -> impl Future< + Output = std::result::Result< + tonic::Response, + tonic::Status, + >, + > + Send; } #[derive(Debug)] pub struct HealthServer { diff --git a/tonic-health/src/server.rs b/tonic-health/src/server.rs index 577eb57c9..520f4ac09 100644 --- a/tonic-health/src/server.rs +++ b/tonic-health/src/server.rs @@ -120,7 +120,6 @@ impl HealthService { } } -#[tonic::async_trait] impl Health for HealthService { async fn check( &self, diff --git a/tonic-reflection/src/generated/grpc_reflection_v1alpha.rs b/tonic-reflection/src/generated/grpc_reflection_v1alpha.rs index 7efa6d51a..37abc81f4 100644 --- a/tonic-reflection/src/generated/grpc_reflection_v1alpha.rs +++ b/tonic-reflection/src/generated/grpc_reflection_v1alpha.rs @@ -268,7 +268,6 @@ pub mod server_reflection_server { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] use tonic::codegen::*; /// Generated trait containing gRPC methods that should be implemented for use with ServerReflectionServer. - #[async_trait] pub trait ServerReflection: Send + Sync + 'static { /// Server streaming response type for the ServerReflectionInfo method. type ServerReflectionInfoStream: tonic::codegen::tokio_stream::Stream< @@ -281,13 +280,15 @@ pub mod server_reflection_server { + 'static; /// The reflection service is structured as a bidirectional stream, ensuring /// all related requests go to a single server. - async fn server_reflection_info( + fn server_reflection_info( &self, request: tonic::Request>, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> impl Future< + Output = std::result::Result< + tonic::Response, + tonic::Status, + >, + > + Send; } #[derive(Debug)] pub struct ServerReflectionServer { diff --git a/tonic-reflection/src/server.rs b/tonic-reflection/src/server.rs index a28380451..35699ab5f 100644 --- a/tonic-reflection/src/server.rs +++ b/tonic-reflection/src/server.rs @@ -316,7 +316,6 @@ struct ReflectionService { state: Arc, } -#[tonic::async_trait] impl ServerReflection for ReflectionService { type ServerReflectionInfoStream = ReceiverStream>; diff --git a/tonic-types/src/generated/types.bin b/tonic-types/src/generated/types.bin index 3b6d259bd..5f331b56e 100644 Binary files a/tonic-types/src/generated/types.bin and b/tonic-types/src/generated/types.bin differ diff --git a/tonic-web/tests/integration/src/lib.rs b/tonic-web/tests/integration/src/lib.rs index 3dcd12d39..b3aaaa3ef 100644 --- a/tonic-web/tests/integration/src/lib.rs +++ b/tonic-web/tests/integration/src/lib.rs @@ -13,7 +13,6 @@ type BoxStream = Pin> + Send + 'stati pub struct Svc; -#[tonic::async_trait] impl Test for Svc { async fn unary_call(&self, req: Request) -> Result, Status> { let req = req.into_inner(); diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 99388e357..18ef475cb 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -23,7 +23,8 @@ repository = "https://github.com/hyperium/tonic" version = "0.11.0" [features] -codegen = ["dep:async-trait"] +codegen = [] +# codegen = ["dep:async-trait"] gzip = ["dep:flate2"] zstd = ["dep:zstd"] default = ["transport", "codegen", "prost"] @@ -64,7 +65,7 @@ tower-service = "0.3" prost = {version = "0.12", default-features = false, features = ["std"], optional = true} # codegen -async-trait = {version = "0.1.13", optional = true} +# async-trait = {version = "0.1.13", optional = true} # transport h2 = {version = "0.3.24", optional = true} diff --git a/tonic/src/codegen.rs b/tonic/src/codegen.rs index 0697d9e21..f75823214 100644 --- a/tonic/src/codegen.rs +++ b/tonic/src/codegen.rs @@ -1,6 +1,5 @@ //! Codegen exports used by `tonic-build`. -pub use async_trait::async_trait; pub use tokio_stream; pub use std::future::Future; diff --git a/tonic/src/lib.rs b/tonic/src/lib.rs index 325c6af47..859ce402a 100644 --- a/tonic/src/lib.rs +++ b/tonic/src/lib.rs @@ -112,11 +112,6 @@ mod response; mod status; mod util; -/// A re-export of [`async-trait`](https://docs.rs/async-trait) for use with codegen. -#[cfg(feature = "codegen")] -#[cfg_attr(docsrs, doc(cfg(feature = "codegen")))] -pub use async_trait::async_trait; - #[doc(inline)] pub use codec::Streaming; pub use extensions::{Extensions, GrpcMethod}; diff --git a/tonic/src/request.rs b/tonic/src/request.rs index 76bf4e9eb..16d9edf69 100644 --- a/tonic/src/request.rs +++ b/tonic/src/request.rs @@ -327,18 +327,16 @@ impl Request { /// And picked up by RPCs: /// /// ```no_run - /// use tonic::{async_trait, Status, Request, Response}; + /// use tonic::{Status, Request, Response}; /// # /// # struct Output {} /// # struct Input; /// # struct MyService; /// # struct MyExtension; - /// # #[async_trait] /// # trait TestService { /// # async fn handler(&self, req: Request) -> Result, Status>; /// # } /// - /// #[async_trait] /// impl TestService for MyService { /// async fn handler(&self, req: Request) -> Result, Status> { /// let value: &MyExtension = req.extensions().get::().unwrap(); diff --git a/tonic/src/server/grpc.rs b/tonic/src/server/grpc.rs index 5330b30ed..8c5caedf8 100644 --- a/tonic/src/server/grpc.rs +++ b/tonic/src/server/grpc.rs @@ -73,10 +73,8 @@ where /// # fn new(svc: T) -> Self { Self(svc) } /// # fn accept_compressed(self, _: CompressionEncoding) -> Self { self } /// # } - /// # #[tonic::async_trait] /// # trait Example {} /// - /// #[tonic::async_trait] /// impl Example for Svc { /// // ... /// } @@ -104,10 +102,8 @@ where /// # fn new(svc: T) -> Self { Self(svc) } /// # fn send_compressed(self, _: CompressionEncoding) -> Self { self } /// # } - /// # #[tonic::async_trait] /// # trait Example {} /// - /// #[tonic::async_trait] /// impl Example for Svc { /// // ... /// } @@ -132,10 +128,8 @@ where /// # fn new(svc: T) -> Self { Self(svc) } /// # fn max_decoding_message_size(self, _: usize) -> Self { self } /// # } - /// # #[tonic::async_trait] /// # trait Example {} /// - /// #[tonic::async_trait] /// impl Example for Svc { /// // ... /// } @@ -162,10 +156,8 @@ where /// # fn new(svc: T) -> Self { Self(svc) } /// # fn max_encoding_message_size(self, _: usize) -> Self { self } /// # } - /// # #[tonic::async_trait] /// # trait Example {} /// - /// #[tonic::async_trait] /// impl Example for Svc { /// // ... /// }