pub struct DynState<T> { /* private fields */ }Expand description
Direct erased-state storage without a runtime borrow checker.
DynState<T> owns T together with an erased runtime state marker. Unlike
SRcRefCell, it is not an aliasing container and does not perform
dynamic borrow checks. Immutable views require &self; mutable views require
&mut self, so Rust’s ordinary borrowing rules provide exclusivity.
This is useful when code needs a runtime-erased state boundary but does not
need shared ownership or interior mutability. Borrowing checks the erased
state marker, then returns the same StorageStateRef/StorageStateMut
based views used by the shared container APIs.
Implementations§
Source§impl<T> DynState<T>where
T: StateMachineImpl,
impl<T> DynState<T>where
T: StateMachineImpl,
Sourcepub fn new<State>(value: T) -> Self
pub fn new<State>(value: T) -> Self
Creates direct erased-state storage from a runtime value in an initial state.
Sourcepub fn from_state<StateMarker>(state: State<SOwned, T, StateMarker>) -> Selfwhere
StateMarker: ConcreteStateTrait,
pub fn from_state<StateMarker>(state: State<SOwned, T, StateMarker>) -> Selfwhere
StateMarker: ConcreteStateTrait,
Moves an owned state token into direct erased-state storage.
Sourcepub fn borrow<RequestedState>(
&self,
) -> Result<SRefView<'_, DynStorage, T, RuntimeStateMarker<RequestedState>>, SharedStateError<Infallible>>where
RequestedState: StateTrait + StateMarker + StateRuntimeMarkerFor<<RequestedState as StateMarker>::Kind>,
RuntimeStateMarker<RequestedState>: SharedBorrowState,
pub fn borrow<RequestedState>(
&self,
) -> Result<SRefView<'_, DynStorage, T, RuntimeStateMarker<RequestedState>>, SharedStateError<Infallible>>where
RequestedState: StateTrait + StateMarker + StateRuntimeMarkerFor<<RequestedState as StateMarker>::Kind>,
RuntimeStateMarker<RequestedState>: SharedBorrowState,
Borrows a read-only typed view if the erased state matches.
Sourcepub fn borrow_mut<RequestedState>(
&mut self,
) -> Result<SMutView<'_, DynStorage, T, RuntimeStateMarker<RequestedState>>, SharedStateError<Infallible>>where
RequestedState: StateTrait + StateMarker + StateRuntimeMarkerFor<<RequestedState as StateMarker>::Kind>,
RuntimeStateMarker<RequestedState>: SharedBorrowState,
pub fn borrow_mut<RequestedState>(
&mut self,
) -> Result<SMutView<'_, DynStorage, T, RuntimeStateMarker<RequestedState>>, SharedStateError<Infallible>>where
RequestedState: StateTrait + StateMarker + StateRuntimeMarkerFor<<RequestedState as StateMarker>::Kind>,
RuntimeStateMarker<RequestedState>: SharedBorrowState,
Borrows a mutable typed view if the erased state matches.
The returned guard commits its final state back into this DynState
when dropped. No runtime borrow checker is involved because creating the
guard requires &mut self.