use quickcheck::{Arbitrary, Gen, StdGen}; use std::ops::Deref; #[derive(Copy, Clone, Debug)] /// quickcheck Arbitrary adaptor - half the size of `T` on average pub struct Small(pub T); impl Deref for Small { type Target = T; fn deref(&self) -> &T { &self.0 } } impl Arbitrary for Small where T: Arbitrary, { fn arbitrary(g: &mut G) -> Self { let sz = g.size() / 2; Small(T::arbitrary(&mut StdGen::new(g, sz))) } fn shrink(&self) -> Box> { Box::new((**self).shrink().map(Small)) } }