pub struct FsStateMgr { /* private fields */ }
Expand description
Implementation of StateMgr that stores state as JSON files on disk.
§Locking
This manager uses a lock file to determine whether it’s allowed to write to the disk. Only one process should write to the disk at a time, though any number may read from the disk.
By default, every FsStateMgr
starts out unlocked, and only able
to read. Use FsStateMgr::try_lock()
to lock it.
§Limitations
-
This manager only accepts objects that can be serialized as JSON documents. Some types (like maps with non-string keys) can’t be serialized as JSON.
-
This manager normalizes keys to an fs-safe format before saving data with them. This keeps you from accidentally creating or reading files elsewhere in the filesystem, but it doesn’t prevent collisions when two keys collapse to the same fs-safe filename. Therefore, you should probably only use ascii keys that are fs-safe on all systems.
NEVER use user-controlled or remote-controlled data for your keys.
Implementations§
Source§impl FsStateMgr
impl FsStateMgr
Sourcepub fn from_path_and_mistrust<P: AsRef<Path>>(
path: P,
mistrust: &Mistrust,
) -> Result<Self, Error>
pub fn from_path_and_mistrust<P: AsRef<Path>>( path: P, mistrust: &Mistrust, ) -> Result<Self, Error>
Construct a new FsStateMgr
to store data in path
.
This function will try to create path
if it does not already
exist.
All files must be “private” according to the rules specified in mistrust
.
Sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
Return the top-level directory for this storage manager.
(This is the same directory passed to
FsStateMgr::from_path_and_mistrust
.)
Trait Implementations§
Source§impl Clone for FsStateMgr
impl Clone for FsStateMgr
Source§fn clone(&self) -> FsStateMgr
fn clone(&self) -> FsStateMgr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for FsStateMgr
impl Debug for FsStateMgr
Source§impl StateMgr for FsStateMgr
impl StateMgr for FsStateMgr
Source§fn try_lock(&self) -> Result<LockStatus, Error>
fn try_lock(&self) -> Result<LockStatus, Error>
Source§fn unlock(&self) -> Result<(), Error>
fn unlock(&self) -> Result<(), Error>
Source§fn load<D>(&self, key: &str) -> Result<Option<D>, Error>where
D: DeserializeOwned,
fn load<D>(&self, key: &str) -> Result<Option<D>, Error>where
D: DeserializeOwned,
key
from the store. Read moreSource§fn create_handle<T>(self, key: impl Into<String>) -> DynStorageHandle<T>
fn create_handle<T>(self, key: impl Into<String>) -> DynStorageHandle<T>
StorageHandle
to store values of particular type
at a particular key.Auto Trait Implementations§
impl Freeze for FsStateMgr
impl !RefUnwindSafe for FsStateMgr
impl Send for FsStateMgr
impl Sync for FsStateMgr
impl Unpin for FsStateMgr
impl !UnwindSafe for FsStateMgr
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more