| 1 |
|
| 2 |
|
| 3 |
use crate::{ |
| 4 |
Error, Result, |
| 5 |
v4::metric::{Metric, MetricType}, |
| 6 |
}; |
| 7 |
use alloc::borrow::ToOwned; |
| 8 |
use core::{fmt, str::FromStr}; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 22 |
pub enum ModifiedPrivilegesRequired { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
NotDefined, |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
s. |
| 33 |
High, |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
Low, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
None, |
| 49 |
} |
| 50 |
|
| 51 |
impl Default for ModifiedPrivilegesRequired { |
| 52 |
fn default() -> Self { |
| 53 |
Self::NotDefined |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
impl Metric for ModifiedPrivilegesRequired { |
| 58 |
const TYPE: MetricType = MetricType::MPR; |
| 59 |
|
| 60 |
fn as_str(self) -> &'static str { |
| 61 |
match self { |
| 62 |
ModifiedPrivilegesRequired::NotDefined => "X", |
| 63 |
ModifiedPrivilegesRequired::None => "N", |
| 64 |
ModifiedPrivilegesRequired::Low => "L", |
| 65 |
ModifiedPrivilegesRequired::High => "H", |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
impl fmt::Display for ModifiedPrivilegesRequired { |
| 71 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 72 |
write!(f, "{}:{}", Self::name(), self.as_str()) |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
impl FromStr for ModifiedPrivilegesRequired { |
| 77 |
type Err = Error; |
| 78 |
|
| 79 |
fn from_str(s: &str) -> Result<Self> { |
| 80 |
match s { |
| 81 |
"X" => Ok(ModifiedPrivilegesRequired::NotDefined), |
| 82 |
"N" => Ok(ModifiedPrivilegesRequired::None), |
| 83 |
"L" => Ok(ModifiedPrivilegesRequired::Low), |
| 84 |
"H" => Ok(ModifiedPrivilegesRequired::High), |
| 85 |
_ => Err(Error::InvalidMetricV4 { |
| 86 |
metric_type: Self::TYPE, |
| 87 |
value: s.to_owned(), |
| 88 |
}), |
| 89 |
} |
| 90 |
} |
| 91 |
} |