Skip to main content

FileBackedValue

Struct FileBackedValue 

Source
pub struct FileBackedValue<T>{ /* private fields */ }

Implementations§

Source§

impl<T> FileBackedValue<T>

Source

pub fn new(filename: &str) -> Self

Source

pub fn new_at(filename: &str, dir: &Path) -> Self

Source

pub fn path(&self) -> PathBuf

Path to the backing file.

Source

pub fn clear(&mut self) -> Result<()>

Clear the currently stored value and remove the backing file.

Source

pub fn set_dirty_time(&mut self, dirty_time: Duration)

If the time since the file was last edited is longer ago than dirty_time, require a recomputation of the value and a writeback to the file. If this value is not set, the file is only ever read once.

Source

pub fn set_dirty(&mut self) -> Option<T>

Make this file dirty, requiring a recomputation the next time a value is get. Returns the currently stored value, if any.

Source

pub fn get(&mut self) -> FileBackedValueResult<Option<&T>>

Get the current value, which might be None if the backing file does not yet exist.

Source

pub fn get_or_insert(&mut self, default: T) -> FileBackedValueResult<&T>

Source

pub fn get_or_insert_with<F>(&mut self, default: F) -> FileBackedValueResult<&T>
where F: FnOnce() -> T,

Source

pub fn insert(&mut self, value: T) -> &T

Inserts value into the option and writes it to the backing file. Returns a mutable reference to the value.

Auto Trait Implementations§

§

impl<T> Freeze for FileBackedValue<T>
where T: Freeze,

§

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

§

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

§

impl<T> Sync for FileBackedValue<T>
where T: Sync,

§

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

§

impl<T> UnsafeUnpin for FileBackedValue<T>
where T: UnsafeUnpin,

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.