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