Skip to main content

StateStorage

Trait StateStorage 

Source
pub trait StateStorage: Sized {
    type Inner<T, S>
       where T: StateMachineImpl;
    type Machine<T>: StateMachineImpl<Standin = T::Standin, Impl = T::Impl, TransitionToken = T::TransitionToken>
       where T: StateMachineImpl;
    type Inference: InferenceKind = OuterInference;
}
Expand description

Storage backend used by State.

State<Storage, T, S> is only a typed view; the actual representation is selected by this trait. The same implementation methods can therefore work for directly owned values, boxed values, pinned values, shared guard views, and discriminated union views as long as they ask for the right capability bound.

Backend authors provide an Inner<T, S> generic associated type. The library retags that Inner after a successful transition, so the backend controls where data is stored while the state-machine contract still controls which retags are legal.

Most users do not implement this trait. They choose one of the built-in storage aliases and write bounds on methods:

use magicstatemachines::{SRef, SMut, State, transition};
use test_def::{InOnline, Online};
use test_def::states::{Authenticated, Connected};

impl Connection {
    fn endpoint<S>(self: &State<S, Self, impl InOnline>) -> &str
    where
        S: SRef,
    {
        &self.endpoint
    }

    fn authenticate<S>(
        self: State<S, Self, Connected>,
        user: String,
    ) -> State<S, Self, Authenticated>
    where
        S: SMut,
    {
        transition!(self, user)
    }
}

Required Associated Types§

Source

type Inner<T, S> where T: StateMachineImpl

Concrete state representation used by this storage backend.

Source

type Machine<T>: StateMachineImpl<Standin = T::Standin, Impl = T::Impl, TransitionToken = T::TransitionToken> where T: StateMachineImpl

Type that carries the state-machine implementation contract.

Provided Associated Types§

Source

type Inference: InferenceKind = OuterInference

Selects how SDiscriminated recovers the current state marker.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl StateStorage for StorageStateOwned

Source§

type Inner<T, S> = StateOwned<T, S> where T: StateMachineImpl

Source§

type Machine<T> = T where T: StateMachineImpl

Source§

impl StateStorage for StorageStateOwnedBox

Source§

type Inner<T, S> = StateOwned<Box<T>, S> where T: StateMachineImpl

Source§

type Machine<T> = Box<T> where T: StateMachineImpl

Source§

impl StateStorage for StorageStateOwnedPinBox

Available on crate feature alloc only.
Source§

type Inner<T, S> = StateOwned<Pin<Box<T>>, S> where T: StateMachineImpl

Source§

type Machine<T> = Pin<Box<T>> where T: StateMachineImpl

Source§

impl<'a, Backend> StateStorage for StorageStateMut<'a, Backend>
where Backend: SharedStorageView + 'a,

Source§

type Inference = InnerInference

Source§

type Inner<T, S> = StateMut<<Backend as SharedStorageView>::WriteGuard<'a, T>, T, S> where T: StateMachineImpl

Source§

type Machine<T> = T where T: StateMachineImpl

Source§

impl<'a, Backend> StateStorage for StorageStateRef<'a, Backend>
where Backend: SharedStorageView + 'a,

Source§

type Inference = InnerInference

Source§

type Inner<T, S> = StateRef<<Backend as SharedStorageView>::ReadGuard<'a, T>, T, S> where T: StateMachineImpl

Source§

type Machine<T> = T where T: StateMachineImpl