Closed rockburning closed 2 months ago
as shown in the above; my struct TaskTest has its own attribute id is string which is common type in strcut; when I want to capture it in the clousure it show the error above;
Hi @rockburning Thank you for the reporting the issue.
We're using Tokio, this uses "task stealing" in terms of how it does async sheduling. That means, a task can move between threads. For Tokio, the struct being passed on should be implementing Copy. Some other async schedulers doesn't use task stealing, which removes the need of Copy.
That means, in practice, that you'll need to either resort to .clones() or to things that use Arc<RwLock<_>> in order to sync sending these structs over threads.
Sorry, this is Rust's fearless concurrency hitting you with this issue.
For references: https://users.rust-lang.org/t/help-with-tokio-rwlock-and-the-copy-trait/48486 https://users.rust-lang.org/t/how-to-pass-struct-to-other-function-that-use-tokio-without-copy-trait/103775/6
Yeah there's plenty of people hitting the same issue.
Feel free to re-open this issue if you think we should handle this differently?
source code
ERRO is
FnMut
closure 297handle
has typeTaskTest
, which does not implement theCopy
traithandle
is moved here