pub struct PhaseStateStore { /* private fields */ }Expand description
Stores serialized phase state for nodes, keyed by phase enum TypeId.
Phase enums generated by macros implement Serialize + Deserialize.
The store serializes them to bytes on set() and deserializes on get(),
so the store itself is serializable without generic parameters.
§Example
ⓘ
let mut store = PhaseStateStore::new();
store.set::<MyPhase>(&MyPhase::GatherMore { position })?;
let phase: MyPhase = store.get::<MyPhase>()?.unwrap();Implementations§
Source§impl PhaseStateStore
impl PhaseStateStore
Sourcepub fn set<T>(&mut self, value: &T) -> Result<(), PhaseStoreError>where
T: Serialize + 'static,
pub fn set<T>(&mut self, value: &T) -> Result<(), PhaseStoreError>where
T: Serialize + 'static,
Store a phase value, serializing it to bytes.
Overwrites any existing phase of the same type.
Sourcepub fn get<T>(&self) -> Result<Option<T>, PhaseStoreError>where
T: for<'de> Deserialize<'de> + 'static,
pub fn get<T>(&self) -> Result<Option<T>, PhaseStoreError>where
T: for<'de> Deserialize<'de> + 'static,
Retrieve and deserialize a phase value by type.
Returns None if no phase of this type is stored.
Sourcepub fn clear<T: 'static>(&mut self)
pub fn clear<T: 'static>(&mut self)
Remove the phase state for a given type (used on complete).
Trait Implementations§
Source§impl Clone for PhaseStateStore
impl Clone for PhaseStateStore
Source§fn clone(&self) -> PhaseStateStore
fn clone(&self) -> PhaseStateStore
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PhaseStateStore
impl Debug for PhaseStateStore
Source§impl Default for PhaseStateStore
impl Default for PhaseStateStore
Source§fn default() -> PhaseStateStore
fn default() -> PhaseStateStore
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for PhaseStateStore
impl<'de> Deserialize<'de> for PhaseStateStore
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for PhaseStateStore
impl RefUnwindSafe for PhaseStateStore
impl Send for PhaseStateStore
impl Sync for PhaseStateStore
impl Unpin for PhaseStateStore
impl UnsafeUnpin for PhaseStateStore
impl UnwindSafe for PhaseStateStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more