pub struct MealyMachineRs<S, I, O> { /* private fields */ }Expand description
A Mealy machine over Rust values: given state S, reads input I, emits output O.
Each step function takes the current state and an input and returns the next state plus an output.
Implementations§
Source§impl<S: Clone + 'static, I: 'static, O: 'static> MealyMachineRs<S, I, O>
impl<S: Clone + 'static, I: 'static, O: 'static> MealyMachineRs<S, I, O>
Sourcepub fn new(state: S, transition: impl Fn(S, I) -> (S, O) + 'static) -> Self
pub fn new(state: S, transition: impl Fn(S, I) -> (S, O) + 'static) -> Self
Create a new Mealy machine with an initial state and transition function.
Sourcepub fn step(&mut self, input: I) -> O
pub fn step(&mut self, input: I) -> O
Step the machine with one input, returning the output and advancing state.
Sourcepub fn run_vec(&mut self, inputs: Vec<I>) -> Vec<O>
pub fn run_vec(&mut self, inputs: Vec<I>) -> Vec<O>
Run the machine over a vector of inputs, collecting outputs.
Sourcepub fn current_state(&self) -> &S
pub fn current_state(&self) -> &S
Get the current state.
Auto Trait Implementations§
impl<S, I, O> Freeze for MealyMachineRs<S, I, O>where
S: Freeze,
impl<S, I, O> !RefUnwindSafe for MealyMachineRs<S, I, O>
impl<S, I, O> !Send for MealyMachineRs<S, I, O>
impl<S, I, O> !Sync for MealyMachineRs<S, I, O>
impl<S, I, O> Unpin for MealyMachineRs<S, I, O>where
S: Unpin,
impl<S, I, O> UnsafeUnpin for MealyMachineRs<S, I, O>where
S: UnsafeUnpin,
impl<S, I, O> !UnwindSafe for MealyMachineRs<S, I, O>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more