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
13pub struct Windows(windows::Windows);
15
16impl OS {
17 pub fn parse(label: &str) -> Result<OS, String> {
18 let os = OperatingSystem::try_from(label)?;
19
20 Ok(OS(os))
21 }
22
23 pub fn vendor(&self) -> String {
24 match &self.0 {
25 OperatingSystem::Windows(w) => w.vendor(),
26 }
27 }
28
29 pub fn product(&self) -> String {
30 match &self.0 {
31 OperatingSystem::Windows(w) => w.product(),
32 }
33 }
34
35 pub fn to_string(&self) -> Vec<String> {
36 match &self.0 {
37 OperatingSystem::Windows(os) => {
38 os.to_string()
39 }
40 }
41 }
42}
43
44impl Windows {
45 pub fn parse(label: &str) -> Result<Windows, String> {
46 let windows = windows::Windows::try_from(label)?;
47
48 Ok(Windows(windows))
49 }
50
51 pub fn vendor(&self) -> String {
52 self.0.vendor()
53 }
54
55 pub fn product(&self) -> String {
56 self.0.product()
57 }
58
59 pub fn to_string(&self) -> Vec<String> {
60 self.0.to_string()
61 }
62}
63
64impl TryFrom<&str> for OperatingSystem {
65 type Error = String;
66
67 fn try_from(value: &str) -> Result<Self, Self::Error> {
68 if let Ok(windows) = windows::Windows::try_from(value) {
69 Ok(OperatingSystem::Windows(Windows(windows)))
70 } else {
71 Err(format!("{} \"{}\"", ERR_UNKNOWN_OS, value))
72 }
73 }
74}
75
76