Skip to content

Commit 993f044

Browse files
meili-bors[bot]ezegrosirevoire
authored
Merge #579
579: add feature for clients that do not implement send r=irevoire a=ezegrosfeld # Pull Request ## Related issue Fixes #577 ## What does this PR do? Some clients do not have Send compatible futures. To fix this I propose adding a feature disabled by default to support this kind of clients like acw, Send should be supported by default. ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: ezegrosfeld <[email protected]> Co-authored-by: Tamo <[email protected]>
2 parents 043a553 + b83b8ae commit 993f044

File tree

7 files changed

+19
-5
lines changed

7 files changed

+19
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ wasm-bindgen-futures = "0.4"
4040
[features]
4141
default = ["reqwest"]
4242
reqwest = ["dep:reqwest", "pin-project-lite", "bytes"]
43+
futures-unsend = []
4344

4445
[dev-dependencies]
4546
futures-await-test = "0.3"

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ Json output:
244244
By default, the SDK uses [`reqwest`](https://docs.rs/reqwest/latest/reqwest/) to make http calls.
245245
The SDK lets you customize the http client by implementing the `HttpClient` trait yourself and
246246
initializing the `Client` with the `new_with_client` method.
247+
You may be interested by the `futures-unsend` feature which lets you specify a non-Send http client.
248+
249+
#### Wasm support <!-- omit in TOC -->
250+
251+
The SDK supports wasm through reqwest. You'll need to enable the `futures-unsend` feature while importing it, though.
247252

248253
## 🌐 Running in the Browser with WASM <!-- omit in TOC -->
249254

examples/cli-app-with-awc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
meilisearch-sdk = { path = "../..", default-features = false }
10+
meilisearch-sdk = { path = "../..", default-features = false, features = ["futures-unsend"] }
1111
futures = "0.3"
1212
serde = { version = "1.0", features = ["derive"] }
1313
serde_json = "1.0"

examples/web_app/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ serde_json = "1.0"
1313
wasm-bindgen = "0.2"
1414
wasm-bindgen-futures = "0.4.18"
1515
yew = {version="0.21", features = ["csr"]}
16-
meilisearch-sdk = {path="../.."}
16+
meilisearch-sdk = { path="../..", features = ["futures-unsend"] }
1717
lazy_static = "1.4"
1818
serde = {version="1.0", features=["derive"]}
1919
web-sys = "0.3"

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@
222222
//! By default, the SDK uses [`reqwest`](https://docs.rs/reqwest/latest/reqwest/) to make http calls.
223223
//! The SDK lets you customize the http client by implementing the `HttpClient` trait yourself and
224224
//! initializing the `Client` with the `new_with_client` method.
225+
//! You may be interested by the `futures-unsend` feature which lets you specify a non-Send http client.
226+
//!
227+
//! ### Wasm support <!-- omit in TOC -->
228+
//!
229+
//! The SDK supports wasm through reqwest. You'll need to enable the `futures-unsend` feature while importing it, though.
225230
#![warn(clippy::all)]
226231
#![allow(clippy::needless_doctest_main)]
227232

src/request.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ impl<Q, B> Method<Q, B> {
6565
}
6666
}
6767

68-
#[async_trait(?Send)]
68+
#[cfg_attr(feature = "futures-unsend", async_trait(?Send))]
69+
#[cfg_attr(not(feature = "futures-unsend"), async_trait)]
6970
pub trait HttpClient: Clone + Send + Sync {
7071
async fn request<Query, Body, Output>(
7172
&self,
@@ -143,7 +144,8 @@ pub fn parse_response<Output: DeserializeOwned>(
143144
}
144145
}
145146

146-
#[async_trait(?Send)]
147+
#[cfg_attr(feature = "futures-unsend", async_trait(?Send))]
148+
#[cfg_attr(not(feature = "futures-unsend"), async_trait)]
147149
impl HttpClient for Infallible {
148150
async fn request<Query, Body, Output>(
149151
&self,

src/reqwest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ impl ReqwestClient {
5050
}
5151
}
5252

53-
#[async_trait(?Send)]
53+
#[cfg_attr(feature = "futures-unsend", async_trait(?Send))]
54+
#[cfg_attr(not(feature = "futures-unsend"), async_trait)]
5455
impl HttpClient for ReqwestClient {
5556
async fn stream_request<
5657
Query: Serialize + Send + Sync,

0 commit comments

Comments
 (0)