]> git.proxmox.com Git - proxmox-backup.git/commitdiff
api-types: impl Display for FilterType
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 4 Jan 2024 10:05:51 +0000 (11:05 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 10 Jan 2024 09:13:45 +0000 (10:13 +0100)
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 <w.bumiller@proxmox.com>
pbs-api-types/src/jobs.rs

index bc5d749bb159ff1580cf832e1661963ce167bc36..798dea0f61d091f06d012978bb1445f6e4149254 100644 (file)
@@ -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)
     }
 }