use crate::error::KeyParseError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Platform {
Windows,
Linux,
MacOS,
}
impl Platform {
pub fn as_str(&self) -> &'static str {
match self {
Platform::Windows => "Windows",
Platform::Linux => "Linux",
Platform::MacOS => "MacOS",
}
}
}
impl std::fmt::Display for Platform {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl std::str::FromStr for Platform {
type Err = KeyParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"windows" | "win" => Ok(Platform::Windows),
"linux" | "unix" => Ok(Platform::Linux),
"macos" | "mac" | "osx" => Ok(Platform::MacOS),
_ => Err(KeyParseError::InvalidPlatform(s.to_string())),
}
}
}