Trait boulder::Generatable
source · [−]pub trait Generatable {
type Generator: Generator<Output = Self>;
fn generator() -> Self::Generator;
}
Expand description
A type that has an associated default Generator
This trait is implemented via the Generatable
derive
macro. It cannot be directly implemented because the library
itself provides a blanket implementation from a more complex
underlying trait MiniGeneratable
, 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
Required Methods
Return this object’s generator.
Example
use boulder::{Generatable, Generator};
struct FooGenerator {
a: i32
};
impl Generator for FooGenerator {
type Output = Foo;
fn generate(&mut self) -> Foo {
self.a += 1;
Foo { a: self.a }
}
}
struct Foo {
a: i32
};
impl Generatable for Foo {
type Generator = FooGenerator;
fn generator() -> Self::Generator {
FooGenerator { a: 0 }
}
}
let mut g = Foo::generator();
assert_eq!(g.generate().a, 1);
assert_eq!(g.generate().a, 2);