From 5475da8ea8184f60b0c54586668f204fe68d1113 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 5 Feb 2025 20:31:34 +0100 Subject: [PATCH] remove async_trait used in generic_server.rs --- Cargo.lock | 4 ---- src/api/admin/api_server.rs | 2 -- src/api/common/Cargo.toml | 1 - src/api/common/generic_server.rs | 12 +++--------- src/api/k2v/Cargo.toml | 1 - src/api/k2v/api_server.rs | 3 --- src/api/s3/Cargo.toml | 1 - src/api/s3/api_server.rs | 3 --- src/net/Cargo.toml | 1 - 9 files changed, 3 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ec6d2c2..ad5d098d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1301,7 +1301,6 @@ dependencies = [ name = "garage_api_common" version = "1.0.1" dependencies = [ - "async-trait", "bytes", "chrono", "crypto-common", @@ -1332,7 +1331,6 @@ dependencies = [ name = "garage_api_k2v" version = "1.0.1" dependencies = [ - "async-trait", "base64 0.21.7", "err-derive", "futures", @@ -1358,7 +1356,6 @@ version = "1.0.1" dependencies = [ "aes-gcm", "async-compression", - "async-trait", "base64 0.21.7", "bytes", "chrono", @@ -1468,7 +1465,6 @@ name = "garage_net" version = "1.0.1" dependencies = [ "arc-swap", - "async-trait", "bytes", "cfg-if", "err-derive", diff --git a/src/api/admin/api_server.rs b/src/api/admin/api_server.rs index e39fa1ba..6f0c474f 100644 --- a/src/api/admin/api_server.rs +++ b/src/api/admin/api_server.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::sync::Arc; use argon2::password_hash::PasswordHash; -use async_trait::async_trait; use http::header::{ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW}; use hyper::{body::Incoming as IncomingBody, Request, Response, StatusCode}; @@ -221,7 +220,6 @@ impl AdminApiServer { } } -#[async_trait] impl ApiHandler for AdminApiServer { const API_NAME: &'static str = "admin"; const API_NAME_DISPLAY: &'static str = "Admin"; diff --git a/src/api/common/Cargo.toml b/src/api/common/Cargo.toml index 842662c4..5b9cf479 100644 --- a/src/api/common/Cargo.toml +++ b/src/api/common/Cargo.toml @@ -18,7 +18,6 @@ garage_model.workspace = true garage_table.workspace = true garage_util.workspace = true -async-trait.workspace = true bytes.workspace = true chrono.workspace = true crypto-common.workspace = true diff --git a/src/api/common/generic_server.rs b/src/api/common/generic_server.rs index d92a3465..6ddc2ff2 100644 --- a/src/api/common/generic_server.rs +++ b/src/api/common/generic_server.rs @@ -4,8 +4,6 @@ use std::os::unix::fs::PermissionsExt; use std::sync::Arc; use std::time::Duration; -use async_trait::async_trait; - use futures::future::Future; use futures::stream::{futures_unordered::FuturesUnordered, StreamExt}; @@ -47,7 +45,6 @@ pub trait ApiError: std::error::Error + Send + Sync + 'static { fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody; } -#[async_trait] pub trait ApiHandler: Send + Sync + 'static { const API_NAME: &'static str; const API_NAME_DISPLAY: &'static str; @@ -56,11 +53,11 @@ pub trait ApiHandler: Send + Sync + 'static { type Error: ApiError; fn parse_endpoint(&self, r: &Request) -> Result; - async fn handle( + fn handle( &self, req: Request, endpoint: Self::Endpoint, - ) -> Result>, Self::Error>; + ) -> impl Future>, Self::Error>> + Send; } pub struct ApiServer { @@ -248,13 +245,11 @@ impl ApiServer { // ==== helper functions ==== -#[async_trait] pub trait Accept: Send + Sync + 'static { type Stream: AsyncRead + AsyncWrite + Send + Sync + 'static; - async fn accept(&self) -> std::io::Result<(Self::Stream, String)>; + fn accept(&self) -> impl Future> + Send; } -#[async_trait] impl Accept for TcpListener { type Stream = TcpStream; async fn accept(&self) -> std::io::Result<(Self::Stream, String)> { @@ -266,7 +261,6 @@ impl Accept for TcpListener { pub struct UnixListenerOn(pub UnixListener, pub String); -#[async_trait] impl Accept for UnixListenerOn { type Stream = UnixStream; async fn accept(&self) -> std::io::Result<(Self::Stream, String)> { diff --git a/src/api/k2v/Cargo.toml b/src/api/k2v/Cargo.toml index d4e26efa..e3ebedca 100644 --- a/src/api/k2v/Cargo.toml +++ b/src/api/k2v/Cargo.toml @@ -19,7 +19,6 @@ garage_table.workspace = true garage_util = { workspace = true, features = [ "k2v" ] } garage_api_common.workspace = true -async-trait.workspace = true base64.workspace = true err-derive.workspace = true tracing.workspace = true diff --git a/src/api/k2v/api_server.rs b/src/api/k2v/api_server.rs index 31e07762..eb276f5b 100644 --- a/src/api/k2v/api_server.rs +++ b/src/api/k2v/api_server.rs @@ -1,7 +1,5 @@ use std::sync::Arc; -use async_trait::async_trait; - use hyper::{body::Incoming as IncomingBody, Method, Request, Response}; use tokio::sync::watch; @@ -48,7 +46,6 @@ impl K2VApiServer { } } -#[async_trait] impl ApiHandler for K2VApiServer { const API_NAME: &'static str = "k2v"; const API_NAME_DISPLAY: &'static str = "K2V"; diff --git a/src/api/s3/Cargo.toml b/src/api/s3/Cargo.toml index a1751c9f..387e45db 100644 --- a/src/api/s3/Cargo.toml +++ b/src/api/s3/Cargo.toml @@ -24,7 +24,6 @@ garage_api_common.workspace = true aes-gcm.workspace = true async-compression.workspace = true -async-trait.workspace = true base64.workspace = true bytes.workspace = true chrono.workspace = true diff --git a/src/api/s3/api_server.rs b/src/api/s3/api_server.rs index ed71b108..bf48bba1 100644 --- a/src/api/s3/api_server.rs +++ b/src/api/s3/api_server.rs @@ -1,7 +1,5 @@ use std::sync::Arc; -use async_trait::async_trait; - use hyper::header; use hyper::{body::Incoming as IncomingBody, Request, Response}; use tokio::sync::watch; @@ -70,7 +68,6 @@ impl S3ApiServer { } } -#[async_trait] impl ApiHandler for S3ApiServer { const API_NAME: &'static str = "s3"; const API_NAME_DISPLAY: &'static str = "S3"; diff --git a/src/net/Cargo.toml b/src/net/Cargo.toml index c2a869bb..c0b47a6e 100644 --- a/src/net/Cargo.toml +++ b/src/net/Cargo.toml @@ -22,7 +22,6 @@ tokio.workspace = true tokio-util.workspace = true tokio-stream.workspace = true -async-trait.workspace = true serde.workspace = true rmp-serde.workspace = true hex.workspace = true