1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
use serde::{Deserialize, Serialize};
use std::str::FromStr;
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
#[serde(rename_all = "snake_case")]
pub enum OsVersion {
Linux,
Macos(MacosVersion),
Windows(WindowsVersion),
}
impl std::fmt::Display for OsVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OsVersion::Linux => f.write_str("Linux"),
OsVersion::Macos(version) => write!(f, "macOS {}", version.major),
OsVersion::Windows(version) => write!(f, "Windows {}", version.major),
}
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct MacosVersion {
pub major: u32,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct WindowsVersion {
pub major: u32,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum Os {
Linux,
Macos,
Windows,
}
impl FromStr for Os {
type Err = Box<dyn std::error::Error>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"linux" => Ok(Os::Linux),
"macos" => Ok(Os::Macos),
"windows" => Ok(Os::Windows),
other => Err(format!("unknown os {other}").into()),
}
}
}
impl std::fmt::Display for Os {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Os::Linux => f.write_str("Linux"),
Os::Macos => f.write_str("macOS"),
Os::Windows => f.write_str("Windows"),
}
}
}
|