use std::fmt;
use crate::utils::{build_env_opt, define_target_enum};
define_target_enum! {
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum Family {
Unix => "unix",
Windows => "windows",
Wasm => "wasm",
}
as_str_doc = "String representing this target family which matches `#[cfg(target_family)]`",
from_str_doc = "Tries to parse the given string as an [`Family`] falling back to [`Family::Other`] for unknown values.",
}
impl Family {
pub fn target() -> Vec<Self> {
build_env_opt("CARGO_CFG_TARGET_FAMILY")
.unwrap_or_default()
.split(',')
.filter(|s| !s.is_empty())
.map(Self::from_str)
.collect()
}
}
impl fmt::Display for Family {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}