Open jakoschiko opened 3 years ago
@BurntSushi
Some questions:
Gen::from_seed
. Is that okay? Or maybe Gen::from_seed_u64
?Gen::new
because it takes a size parameter. Should I add a Default
implementation for Gen
with random seed and default size?Gen::set_size
? Arbitrary::arbitrary
takes a &mut Gen
and this function makes it very easy to change not only the own local size, but also the size of the Arbitrary::arbitrary
caller. Maybe we should provide a Gen::with_size
that returns a copy.Just my thoughts here, but Gen::with_size
seems reasonable here. Maybe even one that takes a closure? I.e., to generate arbitrary vec's with a size parameter of 10:
gen.with_size(10, Vec::arbitrary)
It would be implemented something like
impl Gen {
pub fn with_size<T>(&mut self, size: usize, f: impl FnOnce(&mut Gen) -> T) -> T {
let old_size = self.size;
self.size = size;
let res = f(self);
self.size = old_size;
res
}
}
What's the status of this PR? It would be super useful to have a seedable Gen
.
^ I am also interested in this.
The seed still can't be set by QuickCheck users, but the new Gen constructor is useful for other crates that use QuickCheck only for its Arbitrary trait.
Closes #277