os_identifier/model/
mod.rs1mod windows;
2pub(crate) use windows::*;
3
4const ERR_UNKNOWN_OS: &str = "Unknown operating system:";
5
6pub struct OS(OperatingSystem);
8
9enum OperatingSystem {
10 Windows(Windows),
11}
12
13#[derive(Debug)]
15pub struct Windows(windows::Windows);
16
17impl OS {
18 pub fn parse(label: &str) -> Result<OS, String> {
19 let os = OperatingSystem::try_from(label)?;
20
21 Ok(OS(os))
22 }
23
24 pub fn vendor(&self) -> String {
25 match &self.0 {
26 OperatingSystem::Windows(w) => w.vendor(),
27 }
28 }
29
30 pub fn product(&self) -> String {
31 match &self.0 {
32 OperatingSystem::Windows(w) => w.product(),
33 }
34 }
35
36 pub fn to_string(&self) -> Vec<String> {
37 match &self.0 {
38 OperatingSystem::Windows(os) => {
39 os.to_string()
40 }
41 }
42 }
43}
44
45impl Windows {
46 pub fn parse(label: &str) -> Result<Windows, String> {
47 let windows = windows::Windows::try_from(label)?;
48
49 Ok(Windows(windows))
50 }
51
52 pub fn vendor(&self) -> String {
53 self.0.vendor()
54 }
55
56 pub fn product(&self) -> String {
57 self.0.product()
58 }
59
60 pub fn to_string(&self) -> Vec<String> {
61 self.0.to_string()
62 }
63}
64
65impl TryFrom<&str> for OperatingSystem {
66 type Error = String;
67
68 fn try_from(value: &str) -> Result<Self, Self::Error> {
69 if let Ok(windows) = windows::Windows::try_from(value) {
70 Ok(OperatingSystem::Windows(Windows(windows)))
71 } else {
72 Err(format!("{} \"{}\"", ERR_UNKNOWN_OS, value))
73 }
74 }
75}
76
77