pub struct DeferredGeneratorDefinition<T> { /* private fields */ }Expand description
A deferred generator definition that can produce generator handles before its implementation is known.
Created by deferred(). Call generator() to get
handles that can be passed to other generators, then call set()
to provide the actual implementation. set consumes the definition,
ensuring it can only be called once.
§Panics
Drawing from a generator handle before set() has been
called will panic.
§Example
use hegel::generators::{self as gs, Generator};
enum Tree {
Leaf(i32),
Branch(Box<Tree>, Box<Tree>),
}
let tree = gs::deferred::<Tree>();
let leaf = gs::integers::<i32>().map(Tree::Leaf);
let branch = hegel::tuples!(tree.generator(), tree.generator())
.map(|(l, r)| Tree::Branch(Box::new(l), Box::new(r)));
tree.set(hegel::one_of!(leaf, branch));Implementations§
Source§impl<T: Send + Sync + 'static> DeferredGeneratorDefinition<T>
impl<T: Send + Sync + 'static> DeferredGeneratorDefinition<T>
Sourcepub fn generator(&self) -> BoxedGenerator<'static, T>
pub fn generator(&self) -> BoxedGenerator<'static, T>
Return a generator handle that will delegate to whatever is
eventually passed to set().
Can be called multiple times to produce independent handles that all share the same underlying definition.
Sourcepub fn set(self, generator: impl Generator<T> + 'static)
pub fn set(self, generator: impl Generator<T> + 'static)
Set the implementation for this deferred generator.
All handles previously returned by generator()
will delegate to the provided generator. Consumes the definition,
so it can only be called once.
§Panics
Drawing from a handle before set is called will panic.