1use std::fmt;
2
3use crate::utils::{build_env, define_target_enum};
4
5define_target_enum! {
6 #[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
8 #[non_exhaustive]
9 pub enum Endian {
10 Big => "big",
12 Little => "little",
14 }
15
16 as_str_doc = "String representing this target endianness which matches `#[cfg(target_endian)]`",
17 from_str_doc = "Tries to parse the given string as an [`Endian`] falling back to [`Endian::Other`] for unknown values.",
18}
19
20impl Endian {
21 #[must_use]
23 pub fn target() -> Self {
24 Self::from_str(build_env("CARGO_CFG_TARGET_ENDIAN"))
25 }
26}
27
28impl fmt::Display for Endian {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 f.write_str(self.as_str())
31 }
32}