os_identifier/windows/
mod.rs1mod windows_10;
2mod windows_11;
3mod windows_7;
4mod windows_8;
5mod windows_vista;
6mod windows_xp;
7
8use windows_7::Windows7;
9use windows_8::Windows8;
10use windows_10::Windows10;
11use windows_11::Windows11;
12use windows_vista::WindowsVista;
13use windows_xp::WindowsXP;
14
15#[derive(Debug)]
16pub struct Windows(WindowsClientOS);
17
18impl Windows {
19 pub fn to_string(&self) -> Vec<String> {
20 self.0.to_string()
21 }
22}
23
24impl TryFrom<&str> for Windows {
25 type Error = String;
26
27 fn try_from(value: &str) -> Result<Self, Self::Error> {
28 let os = WindowsClientOS::try_from(value)?;
29 Ok(Self(os))
30 }
31}
32
33#[derive(Debug)]
34enum WindowsClientOS {
35 Windows7(Windows7),
36 Windows8(Windows8),
37 Windows10(Windows10),
38 Windows11(Windows11),
39 WindowsVista(WindowsVista),
40 WindowsXP(WindowsXP),
41}
42
43impl WindowsClientOS {
44 pub fn to_string(&self) -> Vec<String> {
45 match self {
46 WindowsClientOS::Windows7(windows) => windows.to_string(),
47 WindowsClientOS::Windows8(windows) => windows.to_string(),
48 WindowsClientOS::Windows10(windows) => windows.to_string(),
49 WindowsClientOS::Windows11(windows) => windows.to_string(),
50 WindowsClientOS::WindowsVista(windows) => windows.to_string(),
51 WindowsClientOS::WindowsXP(windows) => windows.to_string(),
52 }
53 }
54}
55
56impl TryFrom<&str> for WindowsClientOS {
57 type Error = String;
58
59 fn try_from(value: &str) -> Result<Self, Self::Error> {
60 if let Ok(windows) = Windows11::try_from(value) {
61 Ok(WindowsClientOS::Windows11(windows))
62 } else if let Ok(windows) = Windows10::try_from(value) {
63 Ok(WindowsClientOS::Windows10(windows))
64 } else if let Ok(windows) = Windows8::try_from(value) {
65 Ok(WindowsClientOS::Windows8(windows))
66 } else if let Ok(windows) = Windows7::try_from(value) {
67 Ok(WindowsClientOS::Windows7(windows))
68 } else if let Ok(windows) = WindowsVista::try_from(value) {
69 Ok(WindowsClientOS::WindowsVista(windows))
70 } else if let Ok(windows) = WindowsXP::try_from(value) {
71 Ok(WindowsClientOS::WindowsXP(windows))
72 } else {
73 Err(format!("Not a windows: {}", value))
74 }
75 }
76}