From 01618ea991610d3d59116558567f387b9dbfe0ac Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 4 Jan 2024 11:05:51 +0100 Subject: [PATCH] api-types: impl Display for FilterType as the previous commit: simply keep the previous Display impl and call it from out of the new GroupFilter impl Signed-off-by: Wolfgang Bumiller --- pbs-api-types/src/jobs.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs index bc5d749b..798dea0f 100644 --- a/pbs-api-types/src/jobs.rs +++ b/pbs-api-types/src/jobs.rs @@ -422,6 +422,17 @@ impl std::str::FromStr for FilterType { } } +// used for serializing below, caution! +impl std::fmt::Display for FilterType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + FilterType::BackupType(backup_type) => write!(f, "type:{}", backup_type), + FilterType::Group(backup_group) => write!(f, "group:{}", backup_group), + FilterType::Regex(regex) => write!(f, "regex:{}", regex.as_str()), + } + } +} + #[derive(Clone, Debug)] pub struct GroupFilter { pub is_exclude: bool, @@ -456,12 +467,10 @@ impl std::str::FromStr for GroupFilter { // used for serializing below, caution! impl std::fmt::Display for GroupFilter { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let exclude = if self.is_exclude { "exclude:" } else { "" }; - match &self.filter_type { - FilterType::BackupType(backup_type) => write!(f, "{}type:{}", exclude, backup_type), - FilterType::Group(backup_group) => write!(f, "{}group:{}", exclude, backup_group), - FilterType::Regex(regex) => write!(f, "{}regex:{}", exclude, regex.as_str()), + if self.is_exclude { + f.write_str("exclude:")?; } + std::fmt::Display::fmt(&self.filter_type, f) } }