parent
a0074b8893
commit
0d39cced6b
@ -0,0 +1,40 @@ |
||||
use std::fmt; |
||||
|
||||
use crate::target; |
||||
|
||||
/// An enum representing supported architectures
|
||||
#[derive(Clone, PartialEq, Eq)] |
||||
pub enum Arch { |
||||
/// x86 64-bit
|
||||
X86_64, |
||||
/// x86 32-bit
|
||||
X86, |
||||
/// ARM 64-bit
|
||||
AArch64, |
||||
} |
||||
|
||||
impl Arch { |
||||
/// Gets the current architecture
|
||||
pub fn get() -> Result<Self, failure::Error> { |
||||
if target::x86_64 { |
||||
Ok(Arch::X86_64) |
||||
} else if target::x86 { |
||||
Ok(Arch::X86) |
||||
} else if target::aarch64 { |
||||
Ok(Arch::AArch64) |
||||
} else { |
||||
bail!("Unrecognized target!") |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl fmt::Display for Arch { |
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
||||
let s = match self { |
||||
Arch::X86_64 => "x86-64", |
||||
Arch::X86 => "x86", |
||||
Arch::AArch64 => "aarch64", |
||||
}; |
||||
write!(f, "{}", s) |
||||
} |
||||
} |
@ -0,0 +1,40 @@ |
||||
use std::fmt; |
||||
|
||||
use crate::target; |
||||
|
||||
/// An enum representing supported operating systems
|
||||
#[derive(Clone, PartialEq, Eq)] |
||||
pub enum Os { |
||||
/// Linux operating system
|
||||
Linux, |
||||
/// Macos operating system
|
||||
MacOS, |
||||
/// Windows operating system
|
||||
Windows, |
||||
} |
||||
|
||||
impl Os { |
||||
/// Get the current operating system
|
||||
pub fn get() -> Result<Self, failure::Error> { |
||||
if target::LINUX { |
||||
Ok(Os::Linux) |
||||
} else if target::MACOS { |
||||
Ok(Os::MacOS) |
||||
} else if target::WINDOWS { |
||||
Ok(Os::Windows) |
||||
} else { |
||||
bail!("Unrecognized target!") |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl fmt::Display for Os { |
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
||||
let s = match self { |
||||
Os::Linux => "linux", |
||||
Os::MacOS => "macOS", |
||||
Os::Windows => "windows", |
||||
}; |
||||
write!(f, "{}", s) |
||||
} |
||||
} |
Loading…
Reference in new issue