whoami/
platform.rs

1use std::fmt::{self, Display, Formatter};
2
3/// The underlying platform for a system
4#[allow(missing_docs)]
5#[derive(Debug, PartialEq, Eq, Clone)]
6#[non_exhaustive]
7pub enum Platform {
8    Linux,
9    Bsd,
10    Windows,
11    // FIXME: Non-standard casing; Rename to 'Mac' rather than 'MacOs' in
12    // whoami 2.0.0
13    MacOS,
14    Illumos,
15    Ios,
16    Android,
17    // FIXME: Separate for different Nintendo consoles in whoami 2.0.0,
18    // currently only used for 3DS
19    Nintendo,
20    // FIXME: Currently unused, remove in whoami 2.0.0
21    Xbox,
22    PlayStation,
23    Fuchsia,
24    Redox,
25    Unknown(String),
26}
27
28impl Display for Platform {
29    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
30        if let Self::Unknown(_) = self {
31            f.write_str("Unknown: ")?;
32        }
33
34        f.write_str(match self {
35            Self::Linux => "Linux",
36            Self::Bsd => "BSD",
37            Self::Windows => "Windows",
38            Self::MacOS => "Mac OS",
39            Self::Illumos => "illumos",
40            Self::Ios => "iOS",
41            Self::Android => "Android",
42            Self::Nintendo => "Nintendo",
43            Self::Xbox => "XBox",
44            Self::PlayStation => "PlayStation",
45            Self::Fuchsia => "Fuchsia",
46            Self::Redox => "Redox",
47            Self::Unknown(a) => a,
48        })
49    }
50}