pub struct StateStore { /* private fields */ }Expand description
Reads and writes the state file in one state directory.
Implementations§
Source§impl StateStore
impl StateStore
Sourcepub fn new(dir: impl Into<PathBuf>) -> Self
pub fn new(dir: impl Into<PathBuf>) -> Self
A store for dir/state.json. Nothing is touched until a method is called.
Sourcepub fn load(&self) -> Result<Option<State>, StateError>
pub fn load(&self) -> Result<Option<State>, StateError>
Loads the state, migrating old versions.
Ok(None) means there is no state file yet. A file that exists but cannot be read,
parsed or migrated is a StateError::Load, and it is left exactly as it was: the
caller must not mistake it for a fresh start.
§Errors
StateError::Load for I/O errors, malformed JSON, a root that is not an object, an
unsupported version, and missing or invalid fields.
Sourcepub fn save(&self, state: &State) -> Result<(), StateError>
pub fn save(&self, state: &State) -> Result<(), StateError>
Writes the state atomically: the JSON goes into a private temporary file in the same
directory, is flushed to disk, and then replaces state.json in one step. The
directory is created if needed. On failure no temporary file stays behind and the
previous state.json is untouched.
§Errors
StateError::Save if the state cannot be serialized or the file cannot be written.
Sourcepub fn remove(&self) -> Result<(), StateError>
pub fn remove(&self) -> Result<(), StateError>
Deletes the state file. A missing file is fine.
§Errors
StateError::Remove if the file exists but cannot be deleted.
Trait Implementations§
Source§impl Clone for StateStore
impl Clone for StateStore
Source§fn clone(&self) -> StateStore
fn clone(&self) -> StateStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StateStore
impl Debug for StateStore
impl Eq for StateStore
Source§impl PartialEq for StateStore
impl PartialEq for StateStore
impl StructuralPartialEq for StateStore
Auto Trait Implementations§
impl Freeze for StateStore
impl RefUnwindSafe for StateStore
impl Send for StateStore
impl Sync for StateStore
impl Unpin for StateStore
impl UnsafeUnpin for StateStore
impl UnwindSafe for StateStore
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.