Struct tor_persist::FsStateMgr
source · [−]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
sourceimpl 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
sourceimpl Clone for FsStateMgr
impl Clone for FsStateMgr
sourcefn clone(&self) -> FsStateMgr
fn clone(&self) -> FsStateMgr
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for FsStateMgr
impl Debug for FsStateMgr
sourceimpl StateMgr for FsStateMgr
impl StateMgr for FsStateMgr
sourcefn try_lock(&self) -> Result<LockStatus, Error>
fn try_lock(&self) -> Result<LockStatus, Error>
Try to become a read-write state manager if possible, without blocking. Read more
sourcefn unlock(&self) -> Result<(), Error>
fn unlock(&self) -> Result<(), Error>
Release any locks held and become a read-only state manager again. If no locks were held, do nothing. Read more
sourcefn 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,
Try to load the object with key key
from the store. Read more
sourcefn store<S>(&self, key: &str, val: &S) -> Result<(), Error> where
S: Serialize,
fn store<S>(&self, key: &str, val: &S) -> Result<(), Error> where
S: Serialize,
Try to save val
with key key
in the store. Read more
sourcefn create_handle<T>(self, key: impl Into<String>) -> DynStorageHandle<T> where
Self: Send + Sync + Sized + 'static,
T: Serialize + DeserializeOwned + 'static,
fn create_handle<T>(self, key: impl Into<String>) -> DynStorageHandle<T> where
Self: Send + Sync + Sized + 'static,
T: Serialize + DeserializeOwned + 'static,
Make a new StorageHandle
to store values of particular type
at a particular key. Read more
Auto Trait Implementations
impl RefUnwindSafe for FsStateMgr
impl Send for FsStateMgr
impl Sync for FsStateMgr
impl Unpin for FsStateMgr
impl UnwindSafe for FsStateMgr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more