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 Recovery {
NotDefined,
Automatic,
User,
Irrecoverable,
}
impl Default for Recovery {
fn default() -> Self {
Self::NotDefined
}
}
impl Metric for Recovery {
const TYPE: MetricType = MetricType::R;
fn as_str(self) -> &'static str {
match self {
Recovery::NotDefined => "X",
Recovery::Automatic => "A",
Recovery::User => "U",
Recovery::Irrecoverable => "I",
}
}
}
impl fmt::Display for Recovery {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", Self::name(), self.as_str())
}
}
impl FromStr for Recovery {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"X" => Ok(Recovery::NotDefined),
"A" => Ok(Recovery::Automatic),
"U" => Ok(Recovery::User),
"I" => Ok(Recovery::Irrecoverable),
_ => Err(Error::InvalidMetricV4 {
metric_type: Self::TYPE,
value: s.to_owned(),
}),
}
}
}