pub struct Sample<T, U, V> { /* private fields */ }
Expand description

Collections from an underlying sequence.

Produce collections from a pair of generators, one for the values themselves, one for the size of yielded collection.

Example:

use boulder::{Cycle, Generator, Repeat, Sample};

let mut g = Sample::<_, _, Vec<_>>::new(Cycle::new((1..5).into_iter()), Repeat::new(1usize..3usize));
assert_eq!(g.generate(), vec![1]);
assert_eq!(g.generate(), vec![2, 3]);
assert_eq!(g.generate(), vec![4]);

Implementations

Create a new generator.

The values it yields (of type V) will contain a number of elements of type type T which are determined by the sequence produced by count. The actual elements are generated by value.

Example:

use boulder::{Generator, Inc, Pattern, Sample};

let mut g = Sample::new(
    Pattern!("hello-{}", Inc(2i32)),
    Inc(1usize)
);
let s1: Vec<_> = g.generate();
assert_eq!(s1.len(), 1);
assert_eq!(s1[0], "hello-2".to_string());
let s2 = g.generate();
assert_eq!(s2.len(), 2);
assert_eq!(s2[0], "hello-3".to_string());
assert_eq!(s2[1], "hello-4".to_string());

Trait Implementations

The output type.

Make a new object. Read more

Available on crate feature persian-rug only.

The output type.

Available on crate feature persian-rug only.

Make a new object. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.