Skip to main content

tabnas_alchemy/shared/
scan.rs

1//! `scan-emit`'s step result: the next state and what to emit for it.
2//!
3//! A pure step function takes the state and one item and returns a
4//! [`Transition`]; the operator that owns the state and the iteration is
5//! transduce's `ScanEmit`, which alchemy reaches through
6//! [`Routers::scan_emit`](crate::shared::Routers::scan_emit).
7
8/// The result of one step: the next state and what to emit for it.
9#[derive(Clone, Debug, PartialEq)]
10pub struct Transition<S, O> {
11    pub state: S,
12    pub outputs: Vec<O>,
13}
14
15impl<S, O> Transition<S, O> {
16    pub fn new(state: S, outputs: Vec<O>) -> Self {
17        Transition { state, outputs }
18    }
19
20    /// A step that emits nothing.
21    pub fn stay(state: S) -> Self {
22        Transition {
23            state,
24            outputs: Vec::new(),
25        }
26    }
27
28    /// A step that emits one item.
29    pub fn emit(state: S, output: O) -> Self {
30        Transition {
31            state,
32            outputs: vec![output],
33        }
34    }
35}