pub struct AutoSaved<T> { /* private fields */ }Expand description
A typed value that can be explicitly persisted to a key-value store.
The engine calls Self::persist on every PersistState event when Phase 2 wires events to
storage.
Implementations§
Source§impl<T: Serialize + DeserializeOwned + Send + Sync + 'static> AutoSaved<T>
impl<T: Serialize + DeserializeOwned + Send + Sync + 'static> AutoSaved<T>
Sourcepub async fn open(
store: Arc<dyn KeyValueStore>,
key: impl Into<String>,
default: T,
) -> StorageResult<Self>
pub async fn open( store: Arc<dyn KeyValueStore>, key: impl Into<String>, default: T, ) -> StorageResult<Self>
Opens a persisted value, falling back to default when the key is absent.
Sourcepub async fn update<F: FnOnce(&mut T) + Send>(&self, f: F)
pub async fn update<F: FnOnce(&mut T) + Send>(&self, f: F)
Mutates the current in-memory value without persisting it.
Sourcepub async fn persist(&self) -> StorageResult<()>
pub async fn persist(&self) -> StorageResult<()>
Serializes and persists the current value as JSON.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for AutoSaved<T>
impl<T> !RefUnwindSafe for AutoSaved<T>
impl<T> !UnwindSafe for AutoSaved<T>
impl<T> Send for AutoSaved<T>where
T: Send,
impl<T> Sync for AutoSaved<T>
impl<T> Unpin for AutoSaved<T>where
T: Unpin,
impl<T> UnsafeUnpin for AutoSaved<T>where
T: UnsafeUnpin,
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