pub struct VersionedHash<T: Hash, P: PathType + ?Sized = Path, H: Hasher + Default = DefaultHasher> { /* private fields */ }Expand description
A value with a hash to determine if it has changed.
You can use any hasher that implements std::hash::Hasher and std::default::Default.
By default, it uses std::collections::hash_map::DefaultHasher.
To access the inner value, you can use Deref / DerefMut
or the into_inner method.
§Examples
use std::path::PathBuf;
use dir_structure::versioned_hash::VersionedHash;
let mut vh = VersionedHash::<String>::new_clean(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert!(vh.is_clean());
vh.push_str(" Modified.");
assert!(vh.is_dirty());
assert!(!vh.is_clean());Implementations§
Source§impl<T: Hash, P: PathType + ?Sized, H: Hasher + Default> VersionedHash<T, P, H>
impl<T: Hash, P: PathType + ?Sized, H: Hasher + Default> VersionedHash<T, P, H>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Get the inner value. You can also use Deref / DerefMut
to get references to the inner value.
§Examples
use std::path::PathBuf;
use dir_structure::versioned_hash::VersionedHash;
let vh = VersionedHash::<String>::new_clean(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert_eq!(vh.into_inner(), "Hello, world!".to_owned());
let vh = VersionedHash::<String>::new_dirty(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert_eq!(vh.into_inner(), "Hello, world!".to_owned());Sourcepub fn new_clean(path: P::OwnedPath, value: T) -> Self
pub fn new_clean(path: P::OwnedPath, value: T) -> Self
Create a new clean value.
§Examples
use std::path::PathBuf;
use dir_structure::versioned_hash::VersionedHash;
let vh = VersionedHash::<String>::new_clean(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert!(vh.is_clean());
assert!(!vh.is_dirty());Sourcepub fn new_dirty(path: P::OwnedPath, value: T) -> Self
pub fn new_dirty(path: P::OwnedPath, value: T) -> Self
Create a new dirty value.
§Examples
use std::path::PathBuf;
use dir_structure::versioned_hash::VersionedHash;
let vh = VersionedHash::<String>::new_dirty(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert!(!vh.is_clean());
assert!(vh.is_dirty());Sourcepub fn is_clean(&self) -> bool
pub fn is_clean(&self) -> bool
Checks if the value has been modified since being read. Returns true if the value is clean (i.e., has not been modified). Returns false if the value is dirty (i.e., has been modified).
§Examples
use std::path::PathBuf;
use dir_structure::versioned_hash::VersionedHash;
let vh = VersionedHash::<String>::new_clean(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert!(vh.is_clean());
let vh = VersionedHash::<String>::new_dirty(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert!(!vh.is_clean());Sourcepub fn is_dirty(&self) -> bool
pub fn is_dirty(&self) -> bool
Checks if the value has been modified since being read. Returns true if the value is dirty (i.e., has been modified). Returns false if the value is clean (i.e., has not been modified).
§Examples
use std::path::PathBuf;
use dir_structure::versioned_hash::VersionedHash;
let vh = VersionedHash::<String>::new_clean(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert!(!vh.is_dirty());
let vh = VersionedHash::<String>::new_dirty(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert!(vh.is_dirty());Sourcepub unsafe fn reset(&mut self)
pub unsafe fn reset(&mut self)
Resets the hash to the current value’s hash.
§Safety
This function is unsafe because it can lead to changes not being written if the value has changed. Ideally this function should only be called after writing the value to disk.
§Examples
use std::path::PathBuf;
use dir_structure::versioned_hash::VersionedHash;
let mut vh = VersionedHash::<String>::new_clean(PathBuf::from("test.txt"), "Hello, world!".to_owned());
assert!(vh.is_clean());
vh.push_str(" Modified.");
assert!(vh.is_dirty());
assert!(!vh.is_clean());
unsafe {
vh.reset();
}
assert!(vh.is_clean());
assert!(!vh.is_dirty());Trait Implementations§
Source§impl<'a, T, H, Vfs: VfsAsync + 'a> ReadFromAsync<'a, Vfs> for VersionedHash<T, Vfs::Path, H>
Available on crate feature async only.
impl<'a, T, H, Vfs: VfsAsync + 'a> ReadFromAsync<'a, Vfs> for VersionedHash<T, Vfs::Path, H>
async only.Source§impl<'a, T, H, Vfs: WriteSupportingVfs<'a>> WriteTo<'a, Vfs> for VersionedHash<T, Vfs::Path, H>
impl<'a, T, H, Vfs: WriteSupportingVfs<'a>> WriteTo<'a, Vfs> for VersionedHash<T, Vfs::Path, H>
Source§impl<'a, T, P, H, Vfs: WriteSupportingVfsAsync<Path = P> + 'a> WriteToAsync<'a, Vfs> for VersionedHash<T, P, H>
Available on crate feature async only.
impl<'a, T, P, H, Vfs: WriteSupportingVfsAsync<Path = P> + 'a> WriteToAsync<'a, Vfs> for VersionedHash<T, P, H>
async only.Source§impl<'a, T, H, Vfs: WriteSupportingVfsAsync + 'a> WriteToAsyncRef<'a, Vfs> for VersionedHash<T, Vfs::Path, H>
Available on crate feature async only.
impl<'a, T, H, Vfs: WriteSupportingVfsAsync + 'a> WriteToAsyncRef<'a, Vfs> for VersionedHash<T, Vfs::Path, H>
async only.Auto Trait Implementations§
impl<T, P, H> Freeze for VersionedHash<T, P, H>
impl<T, P, H> RefUnwindSafe for VersionedHash<T, P, H>
impl<T, P, H> Send for VersionedHash<T, P, H>
impl<T, P, H> Sync for VersionedHash<T, P, H>
impl<T, P, H> Unpin for VersionedHash<T, P, H>
impl<T, P, H> UnwindSafe for VersionedHash<T, P, H>
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
Source§impl<T> DirStructureItem for T
impl<T> DirStructureItem for T
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>
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>
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