Skip to content

Commit

Permalink
Add variant matching in try_from(string) for operation
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Jun 26, 2024
1 parent aa0d902 commit 4236405
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions atspi-common/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ pub enum Operation {
Insert,
#[serde(rename = "delete")]
#[serde(alias = "delete/system")]
#[serde(alias = "remove")]
#[serde(alias = "remove/system")]
Delete,
}

impl TryFrom<&str> for Operation {
type Error = crate::AtspiError;
fn try_from(s: &str) -> Result<Operation, Self::Error> {
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"))),

Check warning on line 24 in atspi-common/src/operation.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/operation.rs#L23-L24

Added lines #L23 - L24 were not covered by tests
}
}
}

impl From<Operation> for String {
fn from(op: Operation) -> String {
match op {
Operation::Insert => "add",
Operation::Delete => "delete",
Operation::Insert => "insert",
Operation::Delete => "remove",

Check warning on line 33 in atspi-common/src/operation.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/operation.rs#L33

Added line #L33 was not covered by tests
}
.to_string()
}
Expand Down

0 comments on commit 4236405

Please sign in to comment.