pub struct Versioned<T: DirStructureItem> { /* private fields */ }Expand description
A versioned value. This is a wrapper around a value that will keep track of how many times it has been changed. This is useful to not write the value to disk if it hasn’t changed.
You can get a reference to the value via its Deref implementation, and
you can get a mutable reference to the value via its DerefMut implementation.
The version is incremented every time DerefMut::deref_mut is called.
Alternatively, for Eq types, you can use the Versioned::edit_eq_check
method to edit the value, and it will increment the version if the value has changed.
§Example
use dir_structure::VersionedString;
let mut v = VersionedString::new("value".to_owned(), "path");
assert!(v.is_clean());
assert!(!v.is_dirty());
*v = "new value".to_owned();
assert!(v.is_dirty());Implementations§
Source§impl<T: DirStructureItem> Versioned<T>
impl<T: DirStructureItem> Versioned<T>
Sourcepub fn new(value: T, path: impl Into<PathBuf>) -> Self
pub fn new(value: T, path: impl Into<PathBuf>) -> Self
Creates a new Versioned with the specified value.
The version is set to the default value.
Sourcepub fn edit_eq_check(&mut self, f: impl FnOnce(&mut T))
pub fn edit_eq_check(&mut self, f: impl FnOnce(&mut T))
Edits the value using the provided closure, and increments the version if the value has changed.
§Example
use dir_structure::VersionedString;
let mut v = VersionedString::new("value".to_owned(), "path");
v.edit_eq_check(|s| *s = "value".to_owned());
assert!(v.is_clean());
v.edit_eq_check(|s| *s = "new value".to_owned());
assert!(v.is_dirty());Trait Implementations§
Source§impl<T: DirStructureItem> Deref for Versioned<T>
impl<T: DirStructureItem> Deref for Versioned<T>
Source§impl<T: DirStructureItem> DerefMut for Versioned<T>
impl<T: DirStructureItem> DerefMut for Versioned<T>
Source§impl<T: DirStructureItem> ReadFrom for Versioned<T>
impl<T: DirStructureItem> ReadFrom for Versioned<T>
Auto Trait Implementations§
impl<T> Freeze for Versioned<T>where
T: Freeze,
impl<T> RefUnwindSafe for Versioned<T>where
T: RefUnwindSafe,
impl<T> Send for Versioned<T>where
T: Send,
impl<T> Sync for Versioned<T>where
T: Sync,
impl<T> Unpin for Versioned<T>where
T: Unpin,
impl<T> UnwindSafe for Versioned<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