Skip to main content

MooreMachineRs

Struct MooreMachineRs 

Source
pub struct MooreMachineRs<S, I, O> { /* private fields */ }
Expand description

A Moore machine over Rust values: output depends only on state.

Each transition takes a state and input and returns the next state. The output function maps states to outputs.

Implementations§

Source§

impl<S: 'static, I: 'static, O: 'static> MooreMachineRs<S, I, O>

Source

pub fn new( state: S, transition: impl Fn(&S, I) -> S + 'static, output: impl Fn(&S) -> O + 'static, ) -> Self

Create a new Moore machine.

Source

pub fn read_output(&self) -> O

Read the current output (depends only on state).

Source

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

Advance the machine with one input.

Source

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

Run the machine over a vector of inputs, collecting one output per step.

Source

pub fn state(&self) -> &S

Get the current state.

Auto Trait Implementations§

§

impl<S, I, O> Freeze for MooreMachineRs<S, I, O>
where S: Freeze,

§

impl<S, I, O> !RefUnwindSafe for MooreMachineRs<S, I, O>

§

impl<S, I, O> !Send for MooreMachineRs<S, I, O>

§

impl<S, I, O> !Sync for MooreMachineRs<S, I, O>

§

impl<S, I, O> Unpin for MooreMachineRs<S, I, O>
where S: Unpin,

§

impl<S, I, O> UnsafeUnpin for MooreMachineRs<S, I, O>
where S: UnsafeUnpin,

§

impl<S, I, O> !UnwindSafe for MooreMachineRs<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.