sandbox_runtime/utils/
platform.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Platform {
6 MacOS,
7 Linux,
8}
9
10impl Platform {
11 pub fn current() -> Option<Self> {
13 #[cfg(target_os = "macos")]
14 {
15 Some(Platform::MacOS)
16 }
17 #[cfg(target_os = "linux")]
18 {
19 Some(Platform::Linux)
20 }
21 #[cfg(not(any(target_os = "macos", target_os = "linux")))]
22 {
23 None
24 }
25 }
26
27 pub fn is_supported() -> bool {
29 Self::current().is_some()
30 }
31
32 pub fn name(&self) -> &'static str {
34 match self {
35 Platform::MacOS => "macOS",
36 Platform::Linux => "Linux",
37 }
38 }
39}
40
41pub fn current_platform() -> Option<Platform> {
43 Platform::current()
44}
45
46#[inline]
48pub fn is_macos() -> bool {
49 cfg!(target_os = "macos")
50}
51
52#[inline]
54pub fn is_linux() -> bool {
55 cfg!(target_os = "linux")
56}
57
58pub fn get_arch() -> &'static str {
60 #[cfg(target_arch = "x86_64")]
61 {
62 "x64"
63 }
64 #[cfg(target_arch = "aarch64")]
65 {
66 "arm64"
67 }
68 #[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
69 {
70 "unknown"
71 }
72}