Skip to content

Commit

Permalink
Parameterize Change type
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Feb 22, 2023
1 parent 5b78b99 commit 5732145
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{Apath, Entry, Kind, Owner, Result, UnixMode};
pub struct EntryChange {
pub apath: Apath,
#[serde(flatten)]
pub change: Change,
pub change: Change<EntryMetadata>,
}

impl EntryChange {
Expand Down Expand Up @@ -99,30 +99,21 @@ impl fmt::Display for EntryChange {

#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[serde(tag = "change")]
pub enum Change {
Unchanged {
unchanged: EntryMetadata,
},
Added {
added: EntryMetadata,
},
Deleted {
deleted: EntryMetadata,
},
Changed {
old: EntryMetadata,
new: EntryMetadata,
},
pub enum Change<E> {
Unchanged { unchanged: E },
Added { added: E },
Deleted { deleted: E },
Changed { old: E, new: E },
}

impl Change {
impl<E> Change<E> {
pub fn is_unchanged(&self) -> bool {
matches!(self, Change::Unchanged { .. })
}

/// Return the primary metadata: the new version, unless this entry was
/// deleted in which case the old version.
pub fn primary_metadata(&self) -> &EntryMetadata {
pub fn primary_metadata(&self) -> &E {
match self {
Change::Unchanged { unchanged } => unchanged,
Change::Added { added } => added,
Expand Down

0 comments on commit 5732145

Please sign in to comment.