TryRepeatFromPersianRug

Struct TryRepeatFromPersianRug 

Source
pub struct TryRepeatFromPersianRug<T> { /* private fields */ }
Available on crate feature persian-rug only.
Expand description

Cycle through the existing Proxy<T> items in the context.

Each proxy will be yielded in turn, in insertion order, and then the sequence will repeat. It is safe to insert more values to yield, and they will occur in their natural position when they are reached.

If there are no available items, generate returns None.

Example:

use boulder::{GeneratorWithPersianRug, TryRepeatFromPersianRug};
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 mut g = TryRepeatFromPersianRug::<Foo>::new();

let (f0, _) = g.generate(&mut r);
assert!(f0.is_none());

r.add(Foo { a: 0 });
r.add(Foo { a: 1 });

let (f1, _) = g.generate(&mut r);
assert_eq!(r.get(&f1.unwrap()).a, 0);
let (f2, _) = g.generate(&mut r);
assert_eq!(r.get(&f2.unwrap()).a, 1);
let (f3, _) = g.generate(&mut r);
assert_eq!(f1, f3);

r.add(Foo { a: 2} );
let (f4, _) = g.generate(&mut r);
assert_eq!(f2, f4);
let (f5, _) = g.generate(&mut r);
assert_eq!(r.get(&f5.unwrap()).a, 2);

Implementations§

Source§

impl<T> TryRepeatFromPersianRug<T>

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl<T> Default for TryRepeatFromPersianRug<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<C, T> GeneratorWithPersianRug<C> for TryRepeatFromPersianRug<T>
where C: Context + Owner<T>, T: Contextual<Context = C>,

Source§

type Output = Option<Proxy<T>>

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§

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.