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

Drop async_trait #1556

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
- uses: actions/checkout@v4
- uses: hecrj/setup-rust-action@v2
with:
rust-version: "1.70" # msrv
rust-version: "1.75" # msrv
- name: Install protoc
uses: taiki-e/install-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ For IntelliJ IDEA users, please refer to [this](https://github.com/intellij-rust

### Rust Version

`tonic`'s MSRV is `1.70`.
`tonic`'s MSRV is `1.75`.

```bash
$ rustup update
Expand Down
2 changes: 0 additions & 2 deletions examples/helloworld-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions examples/routeguide-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point>) -> Result<Response<Feature>, Status> {
unimplemented!()
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion examples/src/authentication/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type EchoResult<T> = Result<Response<T>, Status>;
#[derive(Default)]
pub struct EchoServer;

#[tonic::async_trait]
impl pb::echo_server::Echo for EchoServer {
async fn unary_echo(&self, request: Request<EchoRequest>) -> EchoResult<EchoResponse> {
let message = request.into_inner().message;
Expand Down
1 change: 0 additions & 1 deletion examples/src/autoreload/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/blocking/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/cancellation/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/codec_buffers/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use small_buf::{
#[derive(Default)]
pub struct MyGreeter {}

#[tonic::async_trait]
impl Greeter for MyGreeter {
async fn say_hello(
&self,
Expand Down
1 change: 0 additions & 1 deletion examples/src/compression/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions examples/src/dynamic/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type EchoResult<T> = Result<Response<T>, Status>;
#[derive(Default)]
pub struct MyEcho {}

#[tonic::async_trait]
impl Echo for MyEcho {
async fn unary_echo(&self, request: Request<EchoRequest>) -> EchoResult<EchoResponse> {
println!("Got an echo request from {:?}", request.remote_addr());
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/dynamic_load_balance/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EchoRequest>) -> EchoResult<EchoResponse> {
let message = format!("{} (from {})", request.into_inner().message, self.addr);
Expand Down
1 change: 0 additions & 1 deletion examples/src/grpc-web/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/h2c/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/health/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/helloworld/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/hyper_warp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions examples/src/hyper_warp_multiplex/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use echo::{
#[derive(Default)]
pub struct MyGreeter {}

#[tonic::async_trait]
impl Greeter for MyGreeter {
async fn say_hello(
&self,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/interceptor/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/json-codec/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/load_balance/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EchoRequest>) -> EchoResult<EchoResponse> {
let message = format!("{} (from {})", request.into_inner().message, self.addr);
Expand Down
1 change: 0 additions & 1 deletion examples/src/mock/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[derive(Default)]
pub struct MyGreeter {}

#[tonic::async_trait]
impl Greeter for MyGreeter {
async fn say_hello(
&self,
Expand Down
2 changes: 0 additions & 2 deletions examples/src/multiplex/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[derive(Default)]
pub struct MyGreeter {}

#[tonic::async_trait]
impl Greeter for MyGreeter {
async fn say_hello(
&self,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/optional/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/reflection/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/richer-error/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/richer-error/server_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/routeguide/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub struct RouteGuideService {
features: Arc<Vec<Feature>>,
}

#[tonic::async_trait]
impl RouteGuide for RouteGuideService {
async fn get_feature(&self, request: Request<Point>) -> Result<Response<Feature>, Status> {
println!("GetFeature = {:?}", request);
Expand Down
1 change: 0 additions & 1 deletion examples/src/streaming/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EchoRequest>) -> EchoResult<EchoResponse> {
Err(Status::unimplemented("not implemented"))
Expand Down
1 change: 0 additions & 1 deletion examples/src/timeout/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/tls/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type EchoResult<T> = Result<Response<T>, Status>;
#[derive(Default)]
pub struct EchoServer;

#[tonic::async_trait]
impl pb::echo_server::Echo for EchoServer {
async fn unary_echo(&self, request: Request<EchoRequest>) -> EchoResult<EchoResponse> {
let conn_info = request
Expand Down
1 change: 0 additions & 1 deletion examples/src/tls_client_auth/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type EchoResult<T> = Result<Response<T>, Status>;
#[derive(Default)]
pub struct EchoServer;

#[tonic::async_trait]
impl pb::echo_server::Echo for EchoServer {
async fn unary_echo(&self, request: Request<EchoRequest>) -> EchoResult<EchoResponse> {
let certs = request
Expand Down
1 change: 0 additions & 1 deletion examples/src/tls_rustls/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ type EchoResult<T> = Result<Response<T>, Status>;
#[derive(Default)]
pub struct EchoServer;

#[tonic::async_trait]
impl pb::echo_server::Echo for EchoServer {
async fn unary_echo(&self, request: Request<EchoRequest>) -> EchoResult<EchoResponse> {
let conn_info = request.extensions().get::<Arc<ConnInfo>>().unwrap();
Expand Down
1 change: 0 additions & 1 deletion examples/src/tower/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/src/tracing/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion examples/src/uds/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use hello_world::{
#[derive(Default)]
pub struct MyGreeter {}

#[tonic::async_trait]
impl Greeter for MyGreeter {
async fn say_hello(
&self,
Expand Down
2 changes: 0 additions & 2 deletions interop/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Stream<T> =
Pin<Box<dyn tokio_stream::Stream<Item = std::result::Result<T, Status>> + Send + 'static>>;
type BoxFuture<T, E> = Pin<Box<dyn Future<Output = std::result::Result<T, E>> + Send + 'static>>;

#[tonic::async_trait]
impl pb::test_service_server::TestService for TestService {
async fn empty_call(&self, _request: Request<Empty>) -> Result<Empty> {
Ok(Response::new(Empty {}))
Expand Down Expand Up @@ -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<Empty>) -> Result<Empty> {
Err(Status::unimplemented(""))
Expand Down
3 changes: 0 additions & 3 deletions tests/ambiguous_methods/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[macro_use]
extern crate tonic;

tonic::include_proto!("ambiguous_methods");

fn main() {
Expand Down
1 change: 0 additions & 1 deletion tests/compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl Svc {
}
}

#[tonic::async_trait]
impl test_server::Test for Svc {
async fn compress_output_unary(&self, _req: Request<()>) -> Result<Response<SomeData>, Status> {
let data = [0_u8; UNCOMPRESSED_MIN_BODY_SIZE];
Expand Down
2 changes: 0 additions & 2 deletions tests/default_stubs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Stream<Item = Result<(), Status>> + Send + 'static>>;
type BidirectionalStreamStream =
Expand Down Expand Up @@ -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.
}
1 change: 0 additions & 1 deletion tests/integration_tests/tests/client_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Input>) -> Result<Response<Output>, Status> {
match req.metadata().get("x-test") {
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/tests/complex_tower_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Input>) -> Result<Response<Output>, Status> {
unimplemented!()
Expand Down
Loading
Loading