Skip to main content

DynState

Struct DynState 

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

Source

pub fn new<State>(value: T) -> Self
where T::Standin: Initial<State>, State: ConcreteStateTrait,

Creates direct erased-state storage from a runtime value in an initial state.

Source

pub fn from_state<StateMarker>(state: State<SOwned, T, StateMarker>) -> Self
where StateMarker: ConcreteStateTrait,

Moves an owned state token into direct erased-state storage.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for DynState<T>

§

impl<T> !Send for DynState<T>

§

impl<T> !StateClone for DynState<T>

§

impl<T> !StateCopy for DynState<T>

§

impl<T> !Sync for DynState<T>

§

impl<T> !UnwindSafe for DynState<T>

§

impl<T> Freeze for DynState<T>
where T: Freeze,

§

impl<T> Unpin for DynState<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DynState<T>
where T: UnsafeUnpin,

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.