macro_rules! impl_flatmap_step {
($step:ty, $name:literal) => { ... };
}Expand description
Helper macro to implement Step for flatmap steps (1:N mappings).
Flatmap steps expand each input traverser into zero or more output traversers. The step struct must:
- Implement
Clone - Have an
expand(&self, ctx: &ExecutionContext, traverser: Traverser) -> impl Iterator<Item = Traverser>method - Have an
expand_streaming(&self, ctx: &StreamingContext, traverser: Traverser) -> Box<dyn Iterator<Item = Traverser> + Send + 'static>method
§Example
ⓘ
#[derive(Clone)]
struct DuplicateStep {
count: usize,
}
impl DuplicateStep {
fn expand(&self, _ctx: &ExecutionContext, traverser: Traverser) -> impl Iterator<Item = Traverser> {
(0..self.count).map(move |_| traverser.clone())
}
fn expand_streaming(&self, _ctx: &StreamingContext, traverser: Traverser) -> Box<dyn Iterator<Item = Traverser> + Send + 'static> {
let count = self.count;
Box::new((0..count).map(move |_| traverser.clone()))
}
}
impl_flatmap_step!(DuplicateStep, "duplicate");