Skip to main content

MealyMachineRs

Struct MealyMachineRs 

Source
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>

Source

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.

Source

pub fn step(&mut self, input: I) -> O

Step the machine with one input, returning the output and advancing state.

Source

pub fn run_vec(&mut self, inputs: Vec<I>) -> Vec<O>

Run the machine over a vector of inputs, collecting outputs.

Source

pub fn current_state(&self) -> &S

Get the current state.

Source

pub fn reset(&mut self, state: S)

Reset the machine to a new 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.