use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Platform {
Windows,
Android,
Other,
}
impl Platform {
pub const fn current() -> Self {
if cfg!(target_os = "windows") {
Platform::Windows
} else if cfg!(target_os = "android") {
Platform::Android
} else {
Platform::Other
}
}
pub const fn name(self) -> &'static str {
match self {
Platform::Windows => "windows",
Platform::Android => "android",
Platform::Other => "other",
}
}
pub fn parse_target(value: &str) -> Option<Self> {
match value.trim().to_ascii_lowercase().as_str() {
"windows" | "win" => Some(Platform::Windows),
"android" => Some(Platform::Android),
_ => None,
}
}
pub const fn is_mobile(self) -> bool {
matches!(self, Platform::Android)
}
}
impl fmt::Display for Platform {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name())
}
}