Gen

Trait Gen 

Source
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§

Source

fn examples(&self, seed: u64) -> BoxIter<E>

Produce a example iterator from the generator, given a randomization seed.

Source

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§

Source

fn with_shrinker(&self, other_shrink: BoxShrink<E>) -> BoxGen<E>

Bind another shrinker to generator. See gens::other_shrinker.

Source

fn chain(&self, other_gen: BoxGen<E>) -> BoxGen<E>

Concatenate together two generators. See gens::chain.

Trait Implementations§

Source§

impl<E> Debug for dyn Gen<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Clone + 'static> FilterWithGen<E> for dyn Gen<E>

Source§

fn filter<P>(&self, predicate: P) -> BoxGen<E>
where P: Fn(&E) -> bool + Clone + 'static,

Source§

impl<E0: Clone + 'static> MapWithGen<E0> for dyn Gen<E0>

Source§

fn map<E1>(&self, map_fn: fn(E0) -> E1, unmap_fn: fn(E1) -> E0) -> BoxGen<E1>
where E1: Clone + 'static,

Source§

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,

Source§

fn zip_3<E1, E2>( &self, gen1: BoxGen<E1>, gen2: BoxGen<E2>, ) -> BoxGen<(E0, E1, E2)>
where E1: Clone + 'static, E2: Clone + 'static,

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)>
where E1: Clone + 'static, E2: Clone + 'static, E3: Clone + 'static,

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)>
where E1: Clone + 'static, E2: Clone + 'static, E3: Clone + 'static, E4: Clone + 'static,

Zip together 5 generators.
Source§

fn zip_6<E1, E2, E3, E4, E5>( &self, gen1: BoxGen<E1>, gen2: BoxGen<E2>, gen3: BoxGen<E3>, gen4: BoxGen<E4>, gen5: BoxGen<E5>, ) -> BoxGen<(E0, E1, E2, E3, E4, E5)>
where E1: Clone + 'static, E2: Clone + 'static, E3: Clone + 'static, E4: Clone + 'static, E5: Clone + 'static,

Zip together 6 generators.

Implementors§