It’s possible. You can add a Send
constraint to a trait object like this:
let foo = Box::new(Foo { foo: 1 }) as Box<dyn Bar + Send>;
let (tx, rx): (Sender<Box<dyn Bar + Send>>, Receiver<Box<dyn Bar + Send>>) = channel();
More Related Contents:
- What makes something a “trait object”?
- Understanding Traits and Object Safety
- How do I pass Rc to a function accepting Rc?
- Why does using Option::map to Box::new a trait object not work?
- Return local String as a slice (&str)
- How can I swap in a new value for a field in a mutable reference to a structure?
- How do I return a reference to something inside a RefCell without breaking encapsulation?
- How to convert a String into a &’static str
- What’s an idiomatic way to print an iterator separated by spaces in Rust?
- Double mutable borrow error in a loop happens even with NLL on
- What are move semantics in Rust?
- println! error: expected a literal / format argument must be a string literal
- How to return a reference to a sub-value of a value that is under a mutex?
- How do I return an instance of a trait from a method?
- How does Rust provide move semantics?
- How to transform fields during serialization using Serde?
- “borrowed value does not live long enough” when using the builder pattern
- Is it possible to conditionally enable an attribute like `derive`?
- cannot borrow `self.x` as immutable because `*self` is also borrowed as mutable
- Using the same iterator multiple times in Rust
- Thread ” has overflowed its stack when allocating a large array using Box
- How do you enable a Rust “crate feature”?
- How to implement Iterator yielding mutable references [duplicate]
- How can a Rust program access metadata from its Cargo package?
- How can the ref keyword be avoided when pattern matching in a function taking &self or &mut self?
- How to swap two variables?
- Expected bound lifetime parameter, found concrete lifetime [E0271]
- Comparing every element in a vector with the next one
- What is the cited problem with using generic type parameters in trait objects?
- How to concatenate static strings in Rust