pub struct StorageHandle<T> {
instance_dir: CheckedDir,
leafname: String,
marker: PhantomData<fn(T) -> T>,
flock_guard: Arc<LockFileGuard>,
}Expand description
A place in the state or cache directory, where we can load/store a serialisable type
Implies exclusive access.
Rust mutability-xor-sharing rules enforce proper synchronisation,
unless multiple StorageHandles are created
using the same InstanceStateHandle and key.
Fields§
§instance_dir: CheckedDirThe directory and leafname
leafname: StringKEY.json
marker: PhantomData<fn(T) -> T>We can load and store a T.
Invariant in T. But we’re Sync and Send regardless of T.
(From the Table of PhantomData patterns in the Nomicon.)
flock_guard: Arc<LockFileGuard>Clone of the InstanceStateHandle’s lock
Implementations§
Source§impl<T: Serialize + DeserializeOwned> StorageHandle<T>
impl<T: Serialize + DeserializeOwned> StorageHandle<T>
Sourcepub fn load(&self) -> Result<Option<T>>
pub fn load(&self) -> Result<Option<T>>
Load this persistent state
None means the state was most recently deleteed
Sourcefn with_load_store_target<R, F>(&self, action: Action, f: F) -> Result<R>
fn with_load_store_target<R, F>(&self, action: Action, f: F) -> Result<R>
Operate using a load_store::Target
Sourcefn map_err(&self, action: Action) -> impl FnOnce(ErrorSource) -> Error + use<T>
fn map_err(&self, action: Action) -> impl FnOnce(ErrorSource) -> Error + use<T>
Helper to convert an ErrorSource to an Error, if we were performing action
Sourcefn err_resource(&self) -> Resource
fn err_resource(&self) -> Resource
Return the proper Resource for reporting errors
Trait Implementations§
Source§impl<T> ContainsInstanceStateGuard for StorageHandle<T>
impl<T> ContainsInstanceStateGuard for StorageHandle<T>
Source§fn raw_lock_guard(&self) -> Arc<LockFileGuard> ⓘ
fn raw_lock_guard(&self) -> Arc<LockFileGuard> ⓘ
Obtain a raw clone of the underlying filesystem lock Read more
Auto Trait Implementations§
impl<T> Freeze for StorageHandle<T>
impl<T> RefUnwindSafe for StorageHandle<T>
impl<T> Send for StorageHandle<T>
impl<T> Sync for StorageHandle<T>
impl<T> Unpin for StorageHandle<T>
impl<T> UnsafeUnpin for StorageHandle<T>
impl<T> UnwindSafe for StorageHandle<T>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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