diff options
Diffstat (limited to 'vendor/gix-fs/src/snapshot.rs')
-rw-r--r-- | vendor/gix-fs/src/snapshot.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/vendor/gix-fs/src/snapshot.rs b/vendor/gix-fs/src/snapshot.rs index 02a0ec843..2b21d0d9f 100644 --- a/vendor/gix-fs/src/snapshot.rs +++ b/vendor/gix-fs/src/snapshot.rs @@ -10,6 +10,26 @@ pub struct FileSnapshot<T: std::fmt::Debug> { modified: std::time::SystemTime, } +/// Lifecycle +impl<T: std::fmt::Debug> FileSnapshot<T> { + /// A way for users to create 'fake' snapshot from `value` that isn't actually linked to a file on disk. + /// + /// This is useful if there are alternative ways of obtaining the contained instance as fallback to trying + /// to read it from disk. + pub fn new(value: T) -> Self { + FileSnapshot { + value, + modified: std::time::UNIX_EPOCH, + } + } +} + +impl<T: std::fmt::Debug> From<T> for FileSnapshot<T> { + fn from(value: T) -> Self { + FileSnapshot::new(value) + } +} + impl<T: Clone + std::fmt::Debug> Clone for FileSnapshot<T> { fn clone(&self) -> Self { Self { @@ -37,6 +57,12 @@ impl<T: std::fmt::Debug> Deref for FileSnapshot<T> { } } +impl<T: std::fmt::Debug> std::ops::DerefMut for FileSnapshot<T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.value + } +} + impl<T: std::fmt::Debug> Deref for SharedFileSnapshotMut<T> { type Target = MutableOnDemand<Option<SharedFileSnapshot<T>>>; |