use crate::{
Error, Result,
v4::metric::{Metric, MetricType},
};
use alloc::borrow::ToOwned;
use core::{fmt, str::FromStr};
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum ModifiedAttackComplexity {
NotDefined,
High,
Low,
}
impl Default for ModifiedAttackComplexity {
fn default() -> Self {
Self::NotDefined
}
}
impl Metric for ModifiedAttackComplexity {
const TYPE: MetricType = MetricType::MAC;
fn as_str(self) -> &'static str {
match self {
ModifiedAttackComplexity::NotDefined => "X",
ModifiedAttackComplexity::High => "H",
ModifiedAttackComplexity::Low => "L",
}
}
}
impl fmt::Display for ModifiedAttackComplexity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", Self::name(), self.as_str())
}
}
impl FromStr for ModifiedAttackComplexity {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"X" => Ok(ModifiedAttackComplexity::NotDefined),
"H" => Ok(ModifiedAttackComplexity::High),
"L" => Ok(ModifiedAttackComplexity::Low),
_ => Err(Error::InvalidMetricV4 {
metric_type: Self::TYPE,
value: s.to_owned(),
}),
}
}
}