From fe742c62a2ec6bb1dfb5e72dac4dd9a9a03ca5d9 Mon Sep 17 00:00:00 2001 From: Tait Hoyem Date: Wed, 26 Jun 2024 08:49:56 -0600 Subject: [PATCH] Add variant matching in try_from(string) for operation --- atspi-common/src/operation.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/atspi-common/src/operation.rs b/atspi-common/src/operation.rs index ee312f9b..8563ac7b 100644 --- a/atspi-common/src/operation.rs +++ b/atspi-common/src/operation.rs @@ -10,6 +10,8 @@ pub enum Operation { Insert, #[serde(rename = "delete")] #[serde(alias = "delete/system")] + #[serde(alias = "remove")] + #[serde(alias = "remove/system")] Delete, } @@ -17,9 +19,9 @@ impl TryFrom<&str> for Operation { type Error = crate::AtspiError; fn try_from(s: &str) -> Result { match s { - "add" | "add/system" => Ok(Operation::Insert), - "delete" | "delete/system" => Ok(Operation::Delete), - _ => Err(crate::AtspiError::KindMatch(format!("\"{s}\" is not a type of Operation"))), + "add" | "add/system" | "insert" | "insert/system" => Ok(Operation::Insert), + "delete" | "delete/system" | "remove" | "remove/system" => Ok(Operation::Delete), + _ => Err(crate::AtspiError::KindMatch(format!("{s} is not a type of Operation"))), } } } @@ -27,8 +29,8 @@ impl TryFrom<&str> for Operation { impl From for String { fn from(op: Operation) -> String { match op { - Operation::Insert => "add", - Operation::Delete => "delete", + Operation::Insert => "insert", + Operation::Delete => "remove", } .to_string() }