I have the code below. With the commented out parts, it\'s working. When I uncomment the parts it does not compile anymore.
How can I adjust the commented parts to m
I find the error message pretty straightforward:
std::marker::Send is not implemented for Expr + 'staticstd::marker::Send for std::sync::ArcContainerstd::marker::Send for std::sync::Arc[closure@src/main.rs:64:33: 67:6 container1:std::sync::Arc] std::thread::spawnYou are trying to move your Arc to another thread, but it contains an Arc, which cannot be guaranteed to be safely sent (Send) or shared (Sync) across threads.
Either add Send and Sync as supertraits to Expr:
pub trait Expr: Send + Sync { /* ... */ }
Or add them as trait bounds to your trait objects:
pub struct AddExpr {
expr1: Box,
expr2: Box,
}
impl AddExpr {
pub fn new(expr1: Box, expr2: Box) -> Self {
Self { expr1, expr2 }
}
}
struct Container {
x: i32,
cached_expr: Arc,
}
See also: