From aca9222e35d40e0cb7b09c4c10c66c454445b738 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 15 Dec 2022 17:34:13 +0100 Subject: [PATCH] derive Clone and PartialEq for some API types This is useful for react-lik GUI toolkits which need to do VDOM diffs. Signed-off-by: Dietmar Maurer --- pbs-api-types/src/datastore.rs | 10 +++++----- pbs-api-types/src/human_byte.rs | 2 +- pbs-api-types/src/jobs.rs | 19 +++++++++++++++---- pbs-api-types/src/lib.rs | 4 ++-- pbs-api-types/src/remote.rs | 4 ++-- pbs-api-types/src/tape/media.rs | 2 +- pbs-api-types/src/traffic_control.rs | 2 +- pbs-api-types/src/user.rs | 4 ++-- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs index d75ead90..72e8d1ee 100644 --- a/pbs-api-types/src/datastore.rs +++ b/pbs-api-types/src/datastore.rs @@ -270,7 +270,7 @@ pub const DATASTORE_TUNING_STRING_SCHEMA: Schema = StringSchema::new("Datastore }, } )] -#[derive(Serialize, Deserialize, Updater)] +#[derive(Serialize, Deserialize, Updater, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Datastore configuration properties. pub struct DataStoreConfig { @@ -354,7 +354,7 @@ impl DataStoreConfig { } }, )] -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Basic information about a datastore. pub struct DataStoreListItem { @@ -1141,7 +1141,7 @@ pub struct GroupListItem { } #[api()] -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Basic information about a backup namespace. pub struct NamespaceListItem { @@ -1223,7 +1223,7 @@ pub struct TypeCounts { }, }, )] -#[derive(Clone, Default, Serialize, Deserialize)] +#[derive(Clone, Default, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "kebab-case")] /// Garbage collection status. pub struct GarbageCollectionStatus { @@ -1295,7 +1295,7 @@ pub struct DataStoreStatus { }, }, )] -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Status of a Datastore pub struct DataStoreStatusListItem { diff --git a/pbs-api-types/src/human_byte.rs b/pbs-api-types/src/human_byte.rs index f9ac6d53..189a645c 100644 --- a/pbs-api-types/src/human_byte.rs +++ b/pbs-api-types/src/human_byte.rs @@ -121,7 +121,7 @@ fn strip_unit(v: &str) -> (&str, SizeUnit) { } /// Byte size which can be displayed in a human friendly way -#[derive(Debug, Copy, Clone, UpdaterType)] +#[derive(Debug, Copy, Clone, UpdaterType, PartialEq)] pub struct HumanByte { /// The siginficant value, it does not includes any factor of the `unit` size: f64, diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs index 7f029af7..cf7618c4 100644 --- a/pbs-api-types/src/jobs.rs +++ b/pbs-api-types/src/jobs.rs @@ -87,7 +87,7 @@ pub const REMOVE_VANISHED_BACKUPS_SCHEMA: Schema = BooleanSchema::new( }, } )] -#[derive(Serialize, Deserialize, Default)] +#[derive(Serialize, Deserialize, Default, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Job Scheduling Status pub struct JobScheduleStatus { @@ -392,6 +392,17 @@ pub enum GroupFilter { Regex(Regex), } +impl PartialEq for GroupFilter { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Self::BackupType(a), Self::BackupType(b)) => a == b, + (Self::Group(a), Self::Group(b)) => a == b, + (Self::Regex(a), Self::Regex(b)) => a.as_str() == b.as_str(), + _ => false, + } + } +} + impl std::str::FromStr for GroupFilter { type Err = anyhow::Error; @@ -484,7 +495,7 @@ pub const GROUP_FILTER_LIST_SCHEMA: Schema = }, } )] -#[derive(Serialize, Deserialize, Clone, Updater)] +#[derive(Serialize, Deserialize, Clone, Updater, PartialEq)] #[serde(rename_all = "kebab-case")] /// Sync Job pub struct SyncJobConfig { @@ -532,7 +543,7 @@ impl SyncJobConfig { }, }, )] -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Status of Sync Job pub struct SyncJobStatus { @@ -572,7 +583,7 @@ pub struct SyncJobStatus { }, } )] -#[derive(Serialize, Deserialize, Default, Updater)] +#[derive(Serialize, Deserialize, Default, Updater, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Common pruning options pub struct KeepOptions { diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 18cde45e..5e043954 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -492,7 +492,7 @@ pub enum RRDTimeFrame { } #[api] -#[derive(Deserialize, Serialize, PartialEq, Eq)] +#[derive(Deserialize, Serialize, Copy, Clone, PartialEq, Eq)] #[serde(rename_all = "lowercase")] /// type of the realm pub enum RealmType { @@ -518,7 +518,7 @@ pub enum RealmType { }, }, )] -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Basic Information about a realm pub struct BasicRealmInfo { diff --git a/pbs-api-types/src/remote.rs b/pbs-api-types/src/remote.rs index 890e31c0..e7912ee0 100644 --- a/pbs-api-types/src/remote.rs +++ b/pbs-api-types/src/remote.rs @@ -46,7 +46,7 @@ pub const REMOTE_ID_SCHEMA: Schema = StringSchema::new("Remote ID.") }, }, )] -#[derive(Serialize, Deserialize, Updater)] +#[derive(Serialize, Deserialize, Updater, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Remote configuration properties. pub struct RemoteConfig { @@ -96,7 +96,7 @@ pub struct Remote { }, }, )] -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Remote properties. pub struct RemoteWithoutPassword { diff --git a/pbs-api-types/src/tape/media.rs b/pbs-api-types/src/tape/media.rs index c2c25da0..6792cd3c 100644 --- a/pbs-api-types/src/tape/media.rs +++ b/pbs-api-types/src/tape/media.rs @@ -149,7 +149,7 @@ pub struct LabelUuidMap { }, }, )] -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Media content list entry pub struct MediaContentEntry { diff --git a/pbs-api-types/src/traffic_control.rs b/pbs-api-types/src/traffic_control.rs index 3ed579cf..947df38a 100644 --- a/pbs-api-types/src/traffic_control.rs +++ b/pbs-api-types/src/traffic_control.rs @@ -48,7 +48,7 @@ pub const TRAFFIC_CONTROL_BURST_SCHEMA: Schema = }, }, )] -#[derive(Serialize, Deserialize, Default, Clone, Updater)] +#[derive(Serialize, Deserialize, Default, Clone, Updater, PartialEq)] #[serde(rename_all = "kebab-case")] /// Rate Limit Configuration pub struct RateLimitConfig { diff --git a/pbs-api-types/src/user.rs b/pbs-api-types/src/user.rs index 56d82537..a7481190 100644 --- a/pbs-api-types/src/user.rs +++ b/pbs-api-types/src/user.rs @@ -75,7 +75,7 @@ pub const EMAIL_SCHEMA: Schema = StringSchema::new("E-Mail Address.") }, } )] -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] /// User properties with added list of ApiTokens pub struct UserWithTokens { pub userid: Userid, @@ -114,7 +114,7 @@ pub struct UserWithTokens { }, } )] -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, PartialEq)] /// ApiToken properties. pub struct ApiToken { pub tokenid: Authid, -- 2.39.5