AnyModel

Struct AnyModel 

Source
pub struct AnyModel<Substates: ModelState> { /* private fields */ }
Expand description

The following code enables polymorphic handling of different model types and their actions in a state-machine setup. A model is defined in terms of the type of actions it can process, and uses dynamic dispatch to call the correct processing method.

A model implements one of the PureModel, and EffectuflModel traits. Each trait defines a specific Action associated type, and a corresponding processing method (process_pure or process_effectful).

Models implementing the PureModel or EffectfulModel traits are wrapped by the Pure and effectful structs. These are used to implement the PrivateModel trait that provides into_vtable* methods so models can be converted into the AnyModel type.

Finally, the AnyModel type is a central struct that can hold any model and handles actions via its virtual method table. It provides the methods (process_pure, process_effectful) to process different kinds of actions.

Implementations§

Source§

impl<Substates: ModelState> AnyModel<Substates>

Source

pub fn process_pure( &mut self, state: &mut State<Substates>, action: AnyAction, dispatcher: &mut Dispatcher, )

Source

pub fn process_effectful( &mut self, action: AnyAction, dispatcher: &mut Dispatcher, )

Source

pub fn serialize_into( &mut self, writer: &mut BufWriter<File>, action: &AnyAction, )

Source

pub fn deserialize_from(&mut self, reader: &mut BufReader<File>) -> AnyAction

Auto Trait Implementations§

§

impl<Substates> Freeze for AnyModel<Substates>

§

impl<Substates> !RefUnwindSafe for AnyModel<Substates>

§

impl<Substates> !Send for AnyModel<Substates>

§

impl<Substates> !Sync for AnyModel<Substates>

§

impl<Substates> Unpin for AnyModel<Substates>

§

impl<Substates> !UnwindSafe for AnyModel<Substates>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V