Struct Sample

Source
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>
where T: Generator, U: Generator<Output = usize>, V: FromIterator<<T as Generator>::Output> + 'static,

Source

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<T, U, V, X> Generator for Sample<T, U, V>
where T: Generator<Output = X>, U: Generator<Output = usize>, V: FromIterator<X> + 'static,

Source§

type Output = V

The output type.
Source§

fn generate(&mut self) -> Self::Output

Make a new object. Read more
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,

Source§

type Output = V

Available on crate feature persian-rug only.
The output type.
Source§

fn generate<'b, B>(&mut self, context: B) -> (Self::Output, B)
where B: 'b + Mutator<Context = C>,

Available on crate feature persian-rug only.
Make a new object. Read more

Auto Trait Implementations§

§

impl<T, U, V> Freeze for Sample<T, U, V>
where T: Freeze, U: Freeze,

§

impl<T, U, V> RefUnwindSafe for Sample<T, U, V>

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.