pub struct Persist { /* private fields */ }Expand description
Documents in a directory: <name>.json, its backup <name>.json.bak
and, while writing, <name>.json.tmp.
Implementations§
Source§impl Persist
impl Persist
pub fn new(dir: impl Into<PathBuf>) -> Self
pub fn dir(&self) -> &Path
Sourcepub fn save_text(&self, name: &str, text: &str) -> Result<(), PersistError>
pub fn save_text(&self, name: &str, text: &str) -> Result<(), PersistError>
Writes a document’s text atomically, keeping the previous one as
the backup.
A name may hold / (workspaces/photos/layout): its folders are
made.
Sourcepub fn save<T: Serialize>(
&self,
name: &str,
schema: &Schema,
value: &T,
) -> Result<(), PersistError>
pub fn save<T: Serialize>( &self, name: &str, schema: &Schema, value: &T, ) -> Result<(), PersistError>
Saves a document at its schema’s current version.
Sourcepub fn load<T: DeserializeOwned>(
&self,
name: &str,
schema: &Schema,
) -> Result<Option<Read<T>>, PersistError>
pub fn load<T: DeserializeOwned>( &self, name: &str, schema: &Schema, ) -> Result<Option<Read<T>>, PersistError>
Loads a document: None when there is none (neither file exists).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Persist
impl RefUnwindSafe for Persist
impl Send for Persist
impl Sync for Persist
impl Unpin for Persist
impl UnsafeUnpin for Persist
impl UnwindSafe for Persist
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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