Reputation: 5369
I have the following struct :
#[derive(Clone)]
pub struct MyStruct {
function : Box<dyn Fn(Box<dyn Any>) -> Box<dyn Any> + Send + Sync>,
[...]
}
The clone derivation fails because the box isn't Clone
but I don't have a way to make the Fn Clone
, is there a way out of this ? The reason I need clone is that I sometimes pass around &[MyStruct]
and need to clone to own with .to_vec()
...
Upvotes: 2
Views: 189
Reputation: 5369
Simple answer : switch the Box
(a single-owner pointer) to an Rc
or Arc
(shareable pointers)
Upvotes: 3