pub struct File<T> { /* private fields */ }
Expand description
An implementation of Persist
based on an atomically-updated file at a given path.
An exclusive lock is taken using flock(2)
to ensure that concurrent updates cannot
happen, and writes are saved to a staging file before being moved over the old file,
an operation that is atomic on all Unixes.
Implementations§
Source§impl<T: Serialize + DeserializeOwned> File<T>
impl<T: Serialize + DeserializeOwned> File<T>
Trait Implementations§
Source§impl<T: Serialize + DeserializeOwned + Send> Persist for File<T>
impl<T: Serialize + DeserializeOwned + Send> Persist for File<T>
Source§async fn persist(&mut self) -> Result<(), Error>
async fn persist(&mut self) -> Result<(), Error>
Writes the value to disk.
The contents of the file need to be over-written completely, so a temporary file is created as a backup in case a crash occurs while writing to disk.
The temporary file is then renamed to the original filename. If serialization or writing to disk fails, the temporary file is deleted.
Source§fn into_value(self) -> T
fn into_value(self) -> T
Takes the value out, releasing the lock on the persistent file.
type Error = Error
Auto Trait Implementations§
impl<T> Freeze for File<T>where
T: Freeze,
impl<T> RefUnwindSafe for File<T>where
T: RefUnwindSafe,
impl<T> Send for File<T>where
T: Send,
impl<T> Sync for File<T>where
T: Sync,
impl<T> Unpin for File<T>where
T: Unpin,
impl<T> UnwindSafe for File<T>where
T: UnwindSafe,
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