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    Hurd,
26    Unknown(String),
27}
28
29impl Display for Platform {
30    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
31        if let Self::Unknown(_) = self {
32            f.write_str("Unknown: ")?;
33        }
34
35        f.write_str(match self {
36            Self::Linux => "Linux",
37            Self::Bsd => "BSD",
38            Self::Windows => "Windows",
39            Self::MacOS => "Mac OS",
40            Self::Illumos => "illumos",
41            Self::Ios => "iOS",
42            Self::Android => "Android",
43            Self::Nintendo => "Nintendo",
44            Self::Xbox => "XBox",
45            Self::PlayStation => "PlayStation",
46            Self::Fuchsia => "Fuchsia",
47            Self::Redox => "Redox",
48            Self::Hurd => "GNU Hurd",
49            Self::Unknown(a) => a,
50        })
51    }
52}