Struct boulder::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
sourceimpl<T> TryRepeatFromPersianRug<T>
impl<T> TryRepeatFromPersianRug<T>
Trait Implementations
sourceimpl<T> Default for TryRepeatFromPersianRug<T>
impl<T> Default for TryRepeatFromPersianRug<T>
sourceimpl<C, T> GeneratorWithPersianRug<C> for TryRepeatFromPersianRug<T> where
C: Context + Owner<T>,
T: Contextual<Context = C>,
impl<C, T> GeneratorWithPersianRug<C> for TryRepeatFromPersianRug<T> where
C: Context + Owner<T>,
T: Contextual<Context = C>,
Auto Trait Implementations
impl<T> RefUnwindSafe for TryRepeatFromPersianRug<T> where
T: RefUnwindSafe,
impl<T> Send for TryRepeatFromPersianRug<T> where
T: Send,
impl<T> Sync for TryRepeatFromPersianRug<T> where
T: Sync,
impl<T> Unpin for TryRepeatFromPersianRug<T> where
T: Unpin,
impl<T> UnwindSafe for TryRepeatFromPersianRug<T> where
T: 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