1 //! Tag modes.
2 
3 use crate::{Error, ErrorKind, Result};
4 use core::{fmt, str::FromStr};
5 
6 /// Tagging modes: `EXPLICIT` versus `IMPLICIT`.
7 #[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
8 pub enum TagMode {
9     /// `EXPLICIT` tagging.
10     ///
11     /// Tag is added in addition to the inner tag of the type.
12     #[default]
13     Explicit,
14 
15     /// `IMPLICIT` tagging.
16     ///
17     /// Tag replaces the existing tag of the inner type.
18     Implicit,
19 }
20 
21 impl FromStr for TagMode {
22     type Err = Error;
23 
from_str(s: &str) -> Result<Self>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 {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result34     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 }
41