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
sourceimpl<T, U, V> Sample<T, U, V> where
T: Generator,
U: Generator<Output = usize>,
V: FromIterator<<T as Generator>::Output> + 'static,
impl<T, U, V> Sample<T, U, V> where
T: Generator,
U: Generator<Output = usize>,
V: FromIterator<<T as Generator>::Output> + 'static,
sourcepub fn new(value: T, count: U) -> Self
pub fn new(value: T, count: U) -> Self
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
sourceimpl<T, U, V, X> Generator for Sample<T, U, V> where
T: Generator<Output = X>,
U: Generator<Output = usize>,
V: FromIterator<X> + 'static,
impl<T, U, V, X> Generator for Sample<T, U, V> where
T: Generator<Output = X>,
U: Generator<Output = usize>,
V: FromIterator<X> + 'static,
sourceimpl<C, T, U, V, X> GeneratorWithPersianRug<C> for Sample<T, U, V> where
T: GeneratorWithPersianRug<C, Output = X>,
U: GeneratorWithPersianRug<C, Output = usize>,
V: FromIterator<X> + 'static,
C: Context,
impl<C, T, U, V, X> GeneratorWithPersianRug<C> for Sample<T, U, V> where
T: GeneratorWithPersianRug<C, Output = X>,
U: GeneratorWithPersianRug<C, Output = usize>,
V: FromIterator<X> + 'static,
C: Context,
Auto Trait Implementations
impl<T, U, V> RefUnwindSafe for Sample<T, U, V> where
T: RefUnwindSafe,
U: RefUnwindSafe,
V: RefUnwindSafe,
impl<T, U, V> Send for Sample<T, U, V> where
T: Send,
U: Send,
V: Send,
impl<T, U, V> Sync for Sample<T, U, V> where
T: Sync,
U: Sync,
V: Sync,
impl<T, U, V> Unpin for Sample<T, U, V> where
T: Unpin,
U: Unpin,
V: Unpin,
impl<T, U, V> UnwindSafe for Sample<T, U, V> where
T: UnwindSafe,
U: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more