proptest-rs / proptest

Hypothesis-like property testing for Rust
Apache License 2.0
1.63k stars 152 forks source link

Enabling Cloning for BoxedStrategy::Tree with dyn-clone #391

Open Wybxc opened 8 months ago

Wybxc commented 8 months ago

BoxedStrategy::Tree does not implement the Clone trait, which means that any strategy relying on it cannot be verified using check_strategy_sanity.

BoxedStrategy::Tree is represented as a Box<dyn Trait>. To enable it to be cloned, you can use dyn-clone:

trait Trait {}

trait CloneTrait: dyn_clone::DynClone + Trait {}
dyn_clone::clone_trait_object!(CloneTrait);
impl<T> CloneTrait for T where T: Trait + Clone {}

// Now, `Box<dyn CloneTrait>` can be cloned.

Perhaps it would be beneficial to create a new variant of BoxedStrategy where the value tree is guaranteed to implement Clone.

matthew-russo commented 7 months ago

Thanks for reaching out and sorry for the delay. I'll give this a look -- currently triaging whats in our backlog