Skip to content

Commit

Permalink
Use strum to derive Display for ActionAvailability
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Nov 14, 2024
1 parent 50abdd9 commit 83eef66
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/engine/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
use libudev::EventType;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use strum_macros::EnumString;
use strum_macros::{self, EnumString};
use uuid::Uuid;

pub use crate::engine::{
Expand Down Expand Up @@ -360,31 +360,20 @@ impl Deref for DevicePath {
}

/// Represents what actions this pool can accept.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, strum_macros::Display)]
pub enum ActionAvailability {
/// Full set of actions may be taken
#[strum(serialize = "fully_operational")]
Full = 0,
/// No requests via an IPC mechanism may be taken
#[strum(serialize = "no_ipc_requests")]
NoRequests = 1,
/// No changes may be made to the pool including background changes
/// like reacting to devicemapper events
#[strum(serialize = "no_pool_changes")]
NoPoolChanges = 2,
}

impl Display for ActionAvailability {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
ActionAvailability::Full => "fully_operational",
ActionAvailability::NoRequests => "no_ipc_requests",
ActionAvailability::NoPoolChanges => "no_pool_changes",
}
)
}
}

/// Indicates that a property that should be consistent across block devices
/// in a pool may be inconsistent.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down

0 comments on commit 83eef66

Please sign in to comment.