1use anyhow::{bail, Result};
2use std::fmt;
3
4use crate::target;
5
6#[derive(Clone, PartialEq, Eq)]
8pub enum Os {
9 Linux,
11 MacOS,
13 Windows,
15}
16
17impl Os {
18 pub fn get() -> Result<Self> {
20 if target::LINUX {
21 Ok(Os::Linux)
22 } else if target::MACOS {
23 Ok(Os::MacOS)
24 } else if target::WINDOWS {
25 Ok(Os::Windows)
26 } else {
27 bail!("Unrecognized target!")
28 }
29 }
30}
31
32impl fmt::Display for Os {
33 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34 let s = match self {
35 Os::Linux => "linux",
36 Os::MacOS => "macOS",
37 Os::Windows => "windows",
38 };
39 write!(f, "{}", s)
40 }
41}