wasm_pack/install/
os.rs

1use anyhow::{bail, Result};
2use std::fmt;
3
4use crate::target;
5
6/// An enum representing supported operating systems
7#[derive(Clone, PartialEq, Eq)]
8pub enum Os {
9    /// Linux operating system
10    Linux,
11    /// Macos operating system
12    MacOS,
13    /// Windows operating system
14    Windows,
15}
16
17impl Os {
18    /// Get the current operating system
19    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}