From d03cda83213cc8e6733b67f4d65d9645e8fd0e2b Mon Sep 17 00:00:00 2001 From: ezegrosfeld Date: Wed, 1 May 2024 22:52:15 -0300 Subject: [PATCH] add feature for clients that do not implement send --- Cargo.toml | 1 + examples/cli-app-with-awc/Cargo.toml | 2 +- src/request.rs | 6 ++++-- src/reqwest.rs | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9ad71697..749eb665 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ wasm-bindgen-futures = "0.4" [features] default = ["reqwest"] reqwest = ["dep:reqwest", "pin-project-lite", "bytes"] +futures-unsend = [] [dev-dependencies] futures-await-test = "0.3" diff --git a/examples/cli-app-with-awc/Cargo.toml b/examples/cli-app-with-awc/Cargo.toml index a9feddc5..7e08c0e6 100644 --- a/examples/cli-app-with-awc/Cargo.toml +++ b/examples/cli-app-with-awc/Cargo.toml @@ -7,7 +7,7 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -meilisearch-sdk = { path = "../..", default-features = false } +meilisearch-sdk = { path = "../..", default-features = false, features = ["futures-unsend"] } futures = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/request.rs b/src/request.rs index a81e1604..366e51b9 100644 --- a/src/request.rs +++ b/src/request.rs @@ -65,7 +65,8 @@ impl Method { } } -#[async_trait(?Send)] +#[cfg_attr(feature = "futures-unsend", async_trait(?Send))] +#[cfg_attr(not(feature = "futures-unsend"), async_trait)] pub trait HttpClient: Clone + Send + Sync { async fn request( &self, @@ -143,7 +144,8 @@ pub fn parse_response( } } -#[async_trait(?Send)] +#[cfg_attr(feature = "futures-unsend", async_trait(?Send))] +#[cfg_attr(not(feature = "futures-unsend"), async_trait)] impl HttpClient for Infallible { async fn request( &self, diff --git a/src/reqwest.rs b/src/reqwest.rs index 4c239ddb..3198a574 100644 --- a/src/reqwest.rs +++ b/src/reqwest.rs @@ -50,7 +50,8 @@ impl ReqwestClient { } } -#[async_trait(?Send)] +#[cfg_attr(feature = "futures-unsend", async_trait(?Send))] +#[cfg_attr(not(feature = "futures-unsend"), async_trait)] impl HttpClient for ReqwestClient { async fn stream_request< Query: Serialize + Send + Sync,