svd_rs/
endian.rs

1/// Endianness of a [processor](crate::Cpu).
2#[cfg_attr(
3    feature = "serde",
4    derive(serde::Deserialize, serde::Serialize),
5    serde(rename_all = "kebab-case")
6)]
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub enum Endian {
9    /// Little endian.
10    Little,
11    /// Big endian.
12    Big,
13    /// Mixed endian.
14    Selectable,
15    /// Other
16    Other,
17}
18
19impl Default for Endian {
20    fn default() -> Self {
21        Self::Little
22    }
23}
24
25impl Endian {
26    /// Parse a string into an [Endian] value, returning [`Option::None`] if the string is not valid.
27    pub fn parse_str(s: &str) -> Option<Self> {
28        match s {
29            "little" => Some(Self::Little),
30            "big" => Some(Self::Big),
31            "selectable" => Some(Self::Selectable),
32            "other" => Some(Self::Other),
33            _ => None,
34        }
35    }
36
37    /// Convert this [`Endian`] into a static string.
38    pub const fn as_str(self) -> &'static str {
39        match self {
40            Self::Little => "little",
41            Self::Big => "big",
42            Self::Selectable => "selectable",
43            Self::Other => "other",
44        }
45    }
46}