| 1 |
|
| 2 |
|
| 3 |
use crate::{Error, ErrorKind, Result}; |
| 4 |
use core::{fmt, str::FromStr}; |
| 5 |
|
| 6 |
|
| 7 |
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)] |
| 8 |
pub enum TagMode { |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#[default] |
| 13 |
Explicit, |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
Implicit, |
| 19 |
} |
| 20 |
|
| 21 |
impl FromStr for TagMode { |
| 22 |
type Err = Error; |
| 23 |
|
| 24 |
fn from_str(s: &str) -> Result<Self> { |
| 25 |
match s { |
| 26 |
"EXPLICIT" | "explicit" => Ok(TagMode::Explicit), |
| 27 |
"IMPLICIT" | "implicit" => Ok(TagMode::Implicit), |
| 28 |
_ => Err(ErrorKind::TagModeUnknown.into()), |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
impl fmt::Display for TagMode { |
| 34 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 35 |
match self { |
| 36 |
TagMode::Explicit => f.write_str("EXPLICIT"), |
| 37 |
TagMode::Implicit => f.write_str("IMPLICIT"), |
| 38 |
} |
| 39 |
} |
| 40 |
} |