Comments (3)
@irevoire Thank you for that fix, but it turns out something else is still not the same compared to what it used to be and my code still does not compile.
Here's a minimally reproducible program to test against.
use anyhow::Result;
use meilisearch_sdk::{client::Client, indexes::Index};
use serde::Serialize;
#[tokio::main]
async fn main() -> Result<()> {
tokio::spawn(post_documents());
Ok(())
}
#[derive(Serialize)]
struct Doc {
pub id: i32,
pub data: String,
}
async fn post_documents() {
let (_, index) = get_meilisearch_client_and_index().unwrap();
let docs = Vec::<Doc>::new();
let _task = index
.add_documents_in_batches(&docs, Some(5000), Some("id"))
.await;
}
fn get_meilisearch_client_and_index() -> Result<(Client, Index)> {
let meilisearch_url = "...";
let meilisearch_master_key = "...";
let client = Client::new(meilisearch_url, Some(meilisearch_master_key)).unwrap();
let index = client.index("docs");
Ok((client, index))
}
And here's the error:
error[E0277]: `dyn Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>` cannot be sent between threads safely
--> src/main.rs:17:18
|
17 | tokio::spawn(post_documents());
| ------------ ^^^^^^^^^^^^^^^^ `dyn Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>` cannot be sent between threads safely
| |
| required by a bound introduced by this call
|
= help: the trait `Send` is not implemented for `dyn Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>`, which is required by `impl Future<Output = ()>: Send`
= note: required for `Unique<dyn Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>>` to implement `Send`
note: required because it appears within the type `Box<dyn Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>>`
--> /Users/calebwren/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:195:12
|
195 | pub struct Box<
| ^^^
note: required because it appears within the type `Pin<Box<dyn Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>>>`
--> /Users/calebwren/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1090:12
|
1090 | pub struct Pin<Ptr> {
| ^^^
= note: required because it captures the following types: `std::string::String`, `Pin<Box<dyn Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>>>`
note: required because it's used within this `async` fn body
--> /Users/calebwren/.cargo/git/checkouts/meilisearch-rust-2524a391b4e4033d/85ceec4/src/indexes.rs:573:34
|
573 | ) -> Result<TaskInfo, Error> {
| __________________________________^
574 | | let url = if let Some(primary_key) = primary_key {
575 | | format!(
576 | | "{}/indexes/{}/documents?primaryKey={}",
... |
592 | | .await
593 | | }
| |_____^
= note: required because it captures the following types: `impl Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>`
note: required because it's used within this `async` fn body
--> /Users/calebwren/.cargo/git/checkouts/meilisearch-rust-2524a391b4e4033d/85ceec4/src/indexes.rs:667:34
|
667 | ) -> Result<TaskInfo, Error> {
| __________________________________^
668 | | self.add_or_replace(documents, primary_key).await
669 | | }
| |_____^
= note: required because it captures the following types: `&meilisearch_sdk::indexes::Index`, `std::option::Option<&str>`, `Vec<TaskInfo>`, `Chunks<'_, Doc>`, `&mut Vec<TaskInfo>`, `impl Future<Output = Result<TaskInfo, meilisearch_sdk::errors::Error>>`
note: required because it's used within this `async` fn body
--> /Users/calebwren/.cargo/git/checkouts/meilisearch-rust-2524a391b4e4033d/85ceec4/src/indexes.rs:1530:39
|
1530 | ) -> Result<Vec<TaskInfo>, Error> {
| _______________________________________^
1531 | | let mut task = Vec::with_capacity(documents.len());
1532 | | for document_batch in documents.chunks(batch_size.unwrap_or(1000)) {
1533 | | task.push(self.add_documents(document_batch, primary_key).await?);
1534 | | }
1535 | | Ok(task)
1536 | | }
| |_____^
= note: required because it captures the following types: `meilisearch_sdk::indexes::Index`, `Vec<Doc>`, `impl Future<Output = Result<Vec<TaskInfo>, meilisearch_sdk::errors::Error>>`
note: required because it's used within this `async` fn body
--> src/main.rs:28:27
|
28 | async fn post_documents() {
| ___________________________^
29 | | let (_, index) = get_meilisearch_client_and_index().unwrap();
30 | | let docs = Vec::<Doc>::new();
31 | |
... |
34 | | .await;
35 | | }
| |_^
note: required by a bound in `tokio::spawn`
--> /Users/calebwren/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/task/spawn.rs:166:21
|
164 | pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
| ----- required by a bound in this function
165 | where
166 | F: Future + Send + 'static,
| ^^^^ required by this bound in `spawn`
from meilisearch-rust.
Hey @c1wren thanks a lot for trying it out, I believe I fixed your issue in #571
Let me know if anything else is missing before we make a new release.
from meilisearch-rust.
Thanks! I’ll try to look at it this week!
from meilisearch-rust.
Related Issues (20)
- Ensure the error handling are following the best practice HOT 1
- Add CodeCov HOT 2
- Quotation marks in primary silently fails entire `index.add_document` call. HOT 3
- SearchResults<T> doesn't implement trait serde::Serialize HOT 4
- [v1.4] Support text-separator customization
- [v1.4] Support user-dictionary loading HOT 1
- Library seems unusable on MacOS 14.0 HOT 1
- Index::add_documents_csv panics when File streaming HOT 2
- [v1.5] Add a new method for creating snapshots
- [v1.6] Support `proximityPrecision` setting
- [v1.6] support `embedders` setting HOT 3
- The X-MEILI-API-KEY header is missing. Please update the SDK HOT 1
- [v.1.7] Able to use `showRankingScoreDetails` parameter at search
- Streaming in wasm doesn’t work
- Performances: Stop initializing large vector that we’re not going to read
- Unwrap causes panic instead of handling the Result HOT 2
- Implement `std::marker::Send` for SearchResults HOT 4
- http panic in wasm due to capitalized header name HOT 2
- [v1.8] Support `searchCutoffMs` setting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meilisearch-rust.