Skip to content

Commit 2606507

Browse files
Merge pull request #44 from CleverCloud/clg/rm-async-trait
Remove async_trait dependency
2 parents 2ff38df + 39d36b8 commit 2606507

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ keywords = ["clevercloud", "client", "logging", "metrics", "oauth1a"]
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
async-trait = { version = "^0.1.87", optional = true }
1716
base64 = { version = "^0.22.1", optional = true }
1817
bytes = { version = "^1.10.1", features = ["serde"], optional = true }
1918
cidr = { version = "^0.3.1", optional = true }
@@ -49,7 +48,6 @@ uuid = { version = "^1.15.1", features = ["serde", "v4"], optional = true }
4948
[features]
5049
default = ["client", "logging"]
5150
client = [
52-
"async-trait",
5351
"base64",
5452
"bytes",
5553
"cidr",

src/client/mod.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use std::{
99
convert::TryFrom,
1010
error::Error,
1111
fmt::{self, Debug, Display, Formatter},
12+
future::Future,
1213
time::{SystemTime, SystemTimeError},
1314
};
1415
#[cfg(feature = "metrics")]
1516
use std::{sync::LazyLock, time::Instant};
1617

17-
use async_trait::async_trait;
1818
use base64::{Engine, engine::general_purpose::STANDARD as BASE64_ENGINE};
1919
use bytes::Buf;
2020
use crypto_common::InvalidLength;
@@ -65,58 +65,69 @@ static CLIENT_REQUEST_DURATION: LazyLock<CounterVec> = LazyLock::new(|| {
6565

6666
// -----------------------------------------------------------------------------
6767
// Types
68+
6869
type HmacSha512 = Hmac<Sha512>;
6970

7071
// -----------------------------------------------------------------------------
7172
// Request trait
7273

73-
#[async_trait]
7474
pub trait Request {
7575
type Error;
7676

77-
async fn request<T, U>(
77+
fn request<T, U>(
7878
&self,
7979
method: &Method,
8080
endpoint: &str,
8181
payload: &T,
82-
) -> Result<U, Self::Error>
82+
) -> impl Future<Output = Result<U, Self::Error>> + Send
8383
where
8484
T: Serialize + Debug + Send + Sync,
8585
U: DeserializeOwned + Debug + Send + Sync;
8686

87-
async fn execute(&self, request: reqwest::Request) -> Result<reqwest::Response, Self::Error>;
87+
fn execute(
88+
&self,
89+
request: reqwest::Request,
90+
) -> impl Future<Output = Result<reqwest::Response, Self::Error>> + Send;
8891
}
8992

9093
// -----------------------------------------------------------------------------
9194
// RestClient trait
9295

93-
#[async_trait]
94-
pub trait RestClient
95-
where
96-
Self: Debug,
97-
{
96+
pub trait RestClient: Debug {
9897
type Error;
9998

100-
async fn get<T>(&self, endpoint: &str) -> Result<T, Self::Error>
99+
fn get<T>(&self, endpoint: &str) -> impl Future<Output = Result<T, Self::Error>> + Send
101100
where
102101
T: DeserializeOwned + Debug + Send + Sync;
103102

104-
async fn post<T, U>(&self, endpoint: &str, payload: &T) -> Result<U, Self::Error>
103+
fn post<T, U>(
104+
&self,
105+
endpoint: &str,
106+
payload: &T,
107+
) -> impl Future<Output = Result<U, Self::Error>> + Send
105108
where
106109
T: Serialize + Debug + Send + Sync,
107110
U: DeserializeOwned + Debug + Send + Sync;
108111

109-
async fn put<T, U>(&self, endpoint: &str, payload: &T) -> Result<U, Self::Error>
112+
fn put<T, U>(
113+
&self,
114+
endpoint: &str,
115+
payload: &T,
116+
) -> impl Future<Output = Result<U, Self::Error>> + Send
110117
where
111118
T: Serialize + Debug + Send + Sync,
112119
U: DeserializeOwned + Debug + Send + Sync;
113120

114-
async fn patch<T, U>(&self, endpoint: &str, payload: &T) -> Result<U, Self::Error>
121+
fn patch<T, U>(
122+
&self,
123+
endpoint: &str,
124+
payload: &T,
125+
) -> impl Future<Output = Result<U, Self::Error>> + Send
115126
where
116127
T: Serialize + Debug + Send + Sync,
117128
U: DeserializeOwned + Debug + Send + Sync;
118129

119-
async fn delete(&self, endpoint: &str) -> Result<(), Self::Error>;
130+
fn delete(&self, endpoint: &str) -> impl Future<Output = Result<(), Self::Error>> + Send;
120131
}
121132

122133
// -----------------------------------------------------------------------------
@@ -198,10 +209,7 @@ pub const OAUTH1_VERSION: &str = "oauth_version";
198209
pub const OAUTH1_VERSION_1: &str = "1.0";
199210
pub const OAUTH1_TOKEN: &str = "oauth_token";
200211

201-
pub trait OAuth1
202-
where
203-
Self: Debug,
204-
{
212+
pub trait OAuth1: Debug {
205213
type Error;
206214

207215
// `params` returns OAuth1 parameters without the signature one
@@ -432,7 +440,6 @@ pub struct Client {
432440
credentials: Option<Credentials>,
433441
}
434442

435-
#[async_trait]
436443
impl Request for Client {
437444
type Error = ClientError;
438445

@@ -491,7 +498,7 @@ impl Request for Client {
491498
));
492499
}
493500

494-
Ok(serde_json::from_reader(buf.reader()).map_err(ClientError::Deserialize)?)
501+
serde_json::from_reader(buf.reader()).map_err(ClientError::Deserialize)
495502
}
496503

497504
#[cfg_attr(feature = "tracing", tracing::instrument)]
@@ -566,7 +573,6 @@ impl Request for Client {
566573
}
567574
}
568575

569-
#[async_trait]
570576
impl RestClient for Client {
571577
type Error = ClientError;
572578

@@ -597,7 +603,7 @@ impl RestClient for Client {
597603
));
598604
}
599605

600-
Ok(serde_json::from_reader(buf.reader()).map_err(ClientError::Deserialize)?)
606+
serde_json::from_reader(buf.reader()).map_err(ClientError::Deserialize)
601607
}
602608

603609
#[cfg_attr(feature = "tracing", tracing::instrument)]

0 commit comments

Comments
 (0)