Skip to content

Commit 2650843

Browse files
committed
feat: add FileSnapshot::new() to create free-floating instances.
1 parent 8fd7949 commit 2650843

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

gix-fs/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#![deny(rust_2018_idioms, missing_docs)]
33
#![forbid(unsafe_code)]
44

5+
use std::path::PathBuf;
6+
57
/// Common knowledge about the worktree that is needed across most interactions with the work tree
68
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
79
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
@@ -25,9 +27,6 @@ pub struct Capabilities {
2527
mod capabilities;
2628

2729
mod snapshot;
28-
29-
use std::path::PathBuf;
30-
3130
pub use snapshot::{FileSnapshot, SharedFileSnapshot, SharedFileSnapshotMut};
3231

3332
///

gix-fs/src/snapshot.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ pub struct FileSnapshot<T: std::fmt::Debug> {
1010
modified: std::time::SystemTime,
1111
}
1212

13+
/// Lifecycle
14+
impl<T: std::fmt::Debug> FileSnapshot<T> {
15+
/// A way for users to create 'fake' snapshot from `value` that isn't actually linked to a file on disk.
16+
///
17+
/// This is useful if there are alternative ways of obtaining the contained instance as fallback to trying
18+
/// to read it from disk.
19+
pub fn new(value: T) -> Self {
20+
FileSnapshot {
21+
value,
22+
modified: std::time::UNIX_EPOCH,
23+
}
24+
}
25+
}
26+
27+
impl<T: std::fmt::Debug> From<T> for FileSnapshot<T> {
28+
fn from(value: T) -> Self {
29+
FileSnapshot::new(value)
30+
}
31+
}
32+
1333
impl<T: Clone + std::fmt::Debug> Clone for FileSnapshot<T> {
1434
fn clone(&self) -> Self {
1535
Self {

0 commit comments

Comments
 (0)