Skip to content

Commit

Permalink
feat: add FileSnapshot::new() to create free-floating instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 21, 2023
1 parent 8fd7949 commit 2650843
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions gix-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![deny(rust_2018_idioms, missing_docs)]
#![forbid(unsafe_code)]

use std::path::PathBuf;

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

mod snapshot;

use std::path::PathBuf;

pub use snapshot::{FileSnapshot, SharedFileSnapshot, SharedFileSnapshotMut};

///
Expand Down
20 changes: 20 additions & 0 deletions gix-fs/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2650843

Please sign in to comment.