Skip to content

Commit

Permalink
add feature for clients that do not implement send
Browse files Browse the repository at this point in the history
  • Loading branch information
ezegros committed May 2, 2024
1 parent 043a553 commit d03cda8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/cli-app-with-awc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl<Q, B> Method<Q, B> {
}
}

#[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<Query, Body, Output>(
&self,
Expand Down Expand Up @@ -143,7 +144,8 @@ pub fn parse_response<Output: DeserializeOwned>(
}
}

#[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<Query, Body, Output>(
&self,
Expand Down
3 changes: 2 additions & 1 deletion src/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d03cda8

Please sign in to comment.