pub struct SampleFromPersianRug<T, U, V> { /* private fields */ }
Available on crate feature persian-rug only.
Expand description

Produce collections of the existing Proxy<T> items in the context.

It is safe to add more items, and they will occur in their natural place in future items yielded by the generator. The generator argument controls the maximum number of items in each yielded collection. SampleFromPersianRug will always return this maximum if it is possible to do so without duplicating elements.

Example:

use boulder::{GeneratorWithPersianRug, Inc, SampleFromPersianRug};
use persian_rug::{contextual, persian_rug, Context, Proxy};

#[contextual(Rug)]
struct Foo {
  a: i32
}

#[persian_rug]
struct Rug(#[table] Foo);

let mut r = Rug(Default::default());
let f1 = r.add(Foo { a: 0 });
let f2 = r.add(Foo { a: 1 });

let mut g = SampleFromPersianRug::<Foo, _, Vec<_>>::new(Inc(0));
let (s1, _) = g.generate(&mut r);
assert_eq!(s1, Vec::new());
let (s2, _) = g.generate(&mut r);
assert_eq!(s2, vec![ f1 ]);
let (s3, _) = g.generate(&mut r);
assert_eq!(s3, vec![ f2, f1 ]);
let (s4, _) = g.generate(&mut r);
assert_eq!(s4, vec![ f2, f1 ]);

Implementations

Trait Implementations

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.