From 5732145efd7c4c9ad737523790c28a9ee60d524f Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 22 Feb 2023 08:42:04 -0800 Subject: [PATCH] Parameterize Change type --- src/change.rs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/change.rs b/src/change.rs index 65c8608a..9bc88b80 100644 --- a/src/change.rs +++ b/src/change.rs @@ -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, } impl EntryChange { @@ -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 { + Unchanged { unchanged: E }, + Added { added: E }, + Deleted { deleted: E }, + Changed { old: E, new: E }, } -impl Change { +impl Change { 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,