pub(crate) struct Target<'r> {
pub(crate) dir: &'r CheckedDir,
pub(crate) rel_fname: &'r Path,
}Expand description
Common arguments to load/store operations
Fields§
§dir: &'r CheckedDirDirectory
rel_fname: &'r PathFilename relative to dir
Might be a leafname; must be relative
Should include the .json extension.
Implementations§
Source§impl Target<'_>
impl Target<'_>
Sourcepub(crate) fn load<D: DeserializeOwned>(&self) -> Result<Option<D>, ErrorSource>
pub(crate) fn load<D: DeserializeOwned>(&self) -> Result<Option<D>, ErrorSource>
Load and deserialize a D from the file specified by self
Returns None if the file doesn’t exist.
Sourcepub(crate) fn store<S: Serialize>(&self, val: &S) -> Result<(), ErrorSource>
pub(crate) fn store<S: Serialize>(&self, val: &S) -> Result<(), ErrorSource>
Serialise and store an S to the file specified by self
Concurrent readers (using load) will see either the old data,
or the new data,
not corruption or a mixture.
Likewise, if something fails, the old data will remain.
(But, we do not use fsync.)
It is a serious bug to make several concurrent calls to store
for the same file.
That might result in corrupted files.
See fs_mistrust::CheckedDir::write_and_replace
for more details about the semantics.
Sourcepub(crate) fn delete(&self) -> Result<(), ErrorSource>
pub(crate) fn delete(&self) -> Result<(), ErrorSource>
Delete the file specified by self
Trait Implementations§
Auto Trait Implementations§
impl<'r> Freeze for Target<'r>
impl<'r> RefUnwindSafe for Target<'r>
impl<'r> Send for Target<'r>
impl<'r> Sync for Target<'r>
impl<'r> Unpin for Target<'r>
impl<'r> UnsafeUnpin for Target<'r>
impl<'r> UnwindSafe for Target<'r>
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