pub struct AtomicFile<T> { /* private fields */ }
Expand description

This struct provides access to a value of type T which can be persisted to a file in the local filesystem. Access to T is synchronized within the current process, and access to the file is synchronized between processes.

This struct is primarily intended to prevent the file storing T from becoming corrupted if multiple processes attempt to write to it at once.

Implementations§

source§

impl<T: TryDefault + Serialize + DeserializeOwned> AtomicFile<T>

source

pub fn new(path: PathBuf, mask: u32) -> Result<Self>

Creates a new AtomicFile stored at path.

If there is already a file at path then it is opened and a value of type T is deserialized from it. If it does not exist, then a new value of T is created using the TryDefault trait which is then written to a new file at path.

If a new file is created then it’s mode will be masked using mask. This means that if a bit is set in mask then the corresponding mode bit will be unset in the file.

This method will recursively create all parent directories of path if they do not exist.

source

pub fn read(&self) -> Result<AtomicFileReadGuard<'_, T>>

Locks the value of T for reading in the current process and returns a struct which dereferences to it.

source

pub fn write(&self) -> Result<AtomicFileWriteGuard<'_, T>>

Locks the value of T for writing in the current process and returns a struct which dereferences to it.

This struct can be used to save the current value of T to the file.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for AtomicFile<T>where T: RefUnwindSafe,

§

impl<T> Send for AtomicFile<T>where T: Send,

§

impl<T> Sync for AtomicFile<T>where T: Send + Sync,

§

impl<T> Unpin for AtomicFile<T>where T: Unpin,

§

impl<T> UnwindSafe for AtomicFile<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Free for T

§

unsafe default fn free(ptr_ref: NonNull<T>)

Drops the content pointed by this pointer and frees it. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.