1use std::fmt;
2
3use crate::utils::{build_env_opt, define_target_enum};
4
5define_target_enum! {
6 #[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
9 #[non_exhaustive]
10 pub enum Family {
11 Unix => "unix",
13 Windows => "windows",
15 Wasm => "wasm",
17 }
18
19 as_str_doc = "String representing this target family which matches `#[cfg(target_family)]`",
20 from_str_doc = "Tries to parse the given string as an [`Family`] falling back to [`Family::Other`] for unknown values.",
21}
22
23impl Family {
24 pub fn target() -> Vec<Self> {
26 build_env_opt("CARGO_CFG_TARGET_FAMILY")
27 .unwrap_or_default()
28 .split(',')
29 .filter(|s| !s.is_empty())
30 .map(Self::from_str)
31 .collect()
32 }
33}
34
35impl fmt::Display for Family {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 f.write_str(self.as_str())
38 }
39}