Trait boulder::GeneratableWithPersianRug
source · [−]pub trait GeneratableWithPersianRug<C> where
C: Context, {
type Generator: GeneratorWithPersianRug<C, Output = Self>;
fn generator() -> Self::Generator;
}
Available on crate feature
persian-rug
only.Expand description
A type that has an associated default GeneratorWithPersianRug
This trait is implemented via the
GeneratableWithPersianRug
derive macro. It cannot be
directly implemented because the library itself provides a blanket
implementation from a more complex underlying trait
MiniGeneratableWithPersianRug
, which is not currently
documented.
This restriction may be removed in a future version; much of the complexity in this module stems from lacking generic associated types on stable.
Required Associated Types
type Generator: GeneratorWithPersianRug<C, Output = Self>
type Generator: GeneratorWithPersianRug<C, Output = Self>
A default choice of GeneratorWithPersianRug
for this type.
Required Methods
Return this object’s generator.
Example
use boulder::{GeneratableWithPersianRug, GeneratorWithPersianRug};
use persian_rug::{contextual, persian_rug, Context, Mutator};
#[contextual(State)]
struct Foo {
a: i32
}
#[persian_rug]
struct State (
#[table] Foo,
);
struct FooGenerator {
a: i32
};
impl GeneratorWithPersianRug<State> for FooGenerator {
type Output = Foo;
fn generate<'b, B>(&mut self, context: B) -> (Foo, B)
where
B: 'b + Mutator<Context = State>
{
self.a += 1;
(Foo { a: self.a }, context)
}
}
impl GeneratableWithPersianRug<State> for Foo {
type Generator = FooGenerator;
fn generator() -> Self::Generator {
FooGenerator { a: 0 }
}
}
let mut s = State(Default::default());
let mut g = Foo::generator();
let (f1, _) = g.generate(&mut s);
assert_eq!(f1.a, 1);
let (f2, _) = g.generate(&mut s);
assert_eq!(f2.a, 2);