pub trait Gen<E: Clone + 'static>: CloneGen<E> {
// Required methods
fn examples(&self, seed: u64) -> BoxIter<E>;
fn shrinker(&self) -> BoxShrink<E>;
// Provided methods
fn with_shrinker(&self, other_shrink: BoxShrink<E>) -> BoxGen<E> { ... }
fn chain(&self, other_gen: BoxGen<E>) -> BoxGen<E> { ... }
}Expand description
The generator trait, for producing example values to test in a property.
Required Methods§
Sourcefn examples(&self, seed: u64) -> BoxIter<E>
fn examples(&self, seed: u64) -> BoxIter<E>
Produce a example iterator from the generator, given a randomization seed.
Sourcefn shrinker(&self) -> BoxShrink<E>
fn shrinker(&self) -> BoxShrink<E>
Returns a predefined shrinker, or a empty shrinker if no suitable exists.
This enables distributing a default shrinker with given generator, reducing the need to explicitly configure a shrinker at place of use.
When implementing a Gen, you can return a empty shrinks::none shrinker, if that makes the implementation easier, but when you will not get any shrinking functionality applied to failing example.
Provided Methods§
Sourcefn with_shrinker(&self, other_shrink: BoxShrink<E>) -> BoxGen<E>
fn with_shrinker(&self, other_shrink: BoxShrink<E>) -> BoxGen<E>
Bind another shrinker to generator. See gens::other_shrinker.
Sourcefn chain(&self, other_gen: BoxGen<E>) -> BoxGen<E>
fn chain(&self, other_gen: BoxGen<E>) -> BoxGen<E>
Concatenate together two generators. See gens::chain.
Trait Implementations§
Source§impl<E: Clone + 'static> FilterWithGen<E> for dyn Gen<E>
impl<E: Clone + 'static> FilterWithGen<E> for dyn Gen<E>
Source§impl<E0: Clone + 'static> MapWithGen<E0> for dyn Gen<E0>
impl<E0: Clone + 'static> MapWithGen<E0> for dyn Gen<E0>
Source§impl<E0: Clone + 'static> ZipWithGen<E0> for dyn Gen<E0>
impl<E0: Clone + 'static> ZipWithGen<E0> for dyn Gen<E0>
Source§fn zip<E1>(&self, other_gen: BoxGen<E1>) -> BoxGen<(E0, E1)>where
E1: Clone + 'static,
fn zip<E1>(&self, other_gen: BoxGen<E1>) -> BoxGen<(E0, E1)>where
E1: Clone + 'static,
See gens::zip.
Source§fn zip_3<E1, E2>(
&self,
gen1: BoxGen<E1>,
gen2: BoxGen<E2>,
) -> BoxGen<(E0, E1, E2)>
fn zip_3<E1, E2>( &self, gen1: BoxGen<E1>, gen2: BoxGen<E2>, ) -> BoxGen<(E0, E1, E2)>
Zip together 3 generators.
Source§fn zip_4<E1, E2, E3>(
&self,
gen1: BoxGen<E1>,
gen2: BoxGen<E2>,
gen3: BoxGen<E3>,
) -> BoxGen<(E0, E1, E2, E3)>
fn zip_4<E1, E2, E3>( &self, gen1: BoxGen<E1>, gen2: BoxGen<E2>, gen3: BoxGen<E3>, ) -> BoxGen<(E0, E1, E2, E3)>
Zip together 4 generators.
Source§fn zip_5<E1, E2, E3, E4>(
&self,
gen1: BoxGen<E1>,
gen2: BoxGen<E2>,
gen3: BoxGen<E3>,
gen4: BoxGen<E4>,
) -> BoxGen<(E0, E1, E2, E3, E4)>
fn zip_5<E1, E2, E3, E4>( &self, gen1: BoxGen<E1>, gen2: BoxGen<E2>, gen3: BoxGen<E3>, gen4: BoxGen<E4>, ) -> BoxGen<(E0, E1, E2, E3, E4)>
Zip together 5 generators.