drop/desktop/src-tauri/database/src/platform.rs

48 lines
1.3 KiB
Rust
Raw Permalink Normal View History

use serde::{Deserialize, Serialize};
#[derive(Eq, Hash, PartialEq, Serialize, Deserialize, Clone, Copy, Debug, PartialOrd, Ord)]
pub enum Platform {
Windows,
Linux,
2025-11-30 23:12:16 +11:00
#[allow(non_camel_case_types)]
2025-10-16 15:32:28 +11:00
macOS,
}
impl Platform {
#[cfg(target_os = "windows")]
pub const HOST: Platform = Self::Windows;
#[cfg(target_os = "macos")]
2025-10-16 15:32:28 +11:00
pub const HOST: Platform = Self::macOS;
#[cfg(target_os = "linux")]
pub const HOST: Platform = Self::Linux;
pub fn is_case_sensitive(&self) -> bool {
match self {
2025-10-16 15:32:28 +11:00
Self::Windows | Self::macOS => false,
Self::Linux => true,
}
}
}
impl From<&str> for Platform {
fn from(value: &str) -> Self {
match value.to_lowercase().trim() {
"windows" => Self::Windows,
"linux" => Self::Linux,
2025-10-16 15:32:28 +11:00
"mac" | "macos" => Self::macOS,
_ => unimplemented!(),
}
}
}
impl From<whoami::Platform> for Platform {
fn from(value: whoami::Platform) -> Self {
match value {
whoami::Platform::Windows => Platform::Windows,
whoami::Platform::Linux => Platform::Linux,
2025-10-16 15:32:28 +11:00
whoami::Platform::MacOS => Platform::macOS,
platform => unimplemented!("Playform {} is not supported", platform),
}
}
}