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§
Source§impl<T, U, V> Sample<T, U, V>
impl<T, U, V> Sample<T, U, V>
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§
Source§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,
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> Freeze for Sample<T, U, V>
impl<T, U, V> RefUnwindSafe for Sample<T, U, V>
impl<T, U, V> Send for Sample<T, U, V>
impl<T, U, V> Sync for Sample<T, U, V>
impl<T, U, V> Unpin for Sample<T, U, V>
impl<T, U, V> UnwindSafe for Sample<T, U, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more