mod windows;
pub(crate) use windows::*;
const ERR_UNKNOWN_OS: &str = "Unknown operating system:";
#[derive(Debug)]
pub struct OS(OperatingSystem);
#[derive(Debug)]
enum OperatingSystem {
Windows(Windows),
}
#[derive(Debug)]
pub struct Windows(windows::Windows);
impl OS {
pub fn parse(label: &str) -> Result<OS, String> {
let os = OperatingSystem::try_from(label)?;
Ok(OS(os))
}
pub fn vendor(&self) -> String {
match &self.0 {
OperatingSystem::Windows(w) => w.vendor(),
}
}
pub fn product(&self) -> String {
match &self.0 {
OperatingSystem::Windows(w) => w.product(),
}
}
pub fn to_string(&self) -> Vec<String> {
match &self.0 {
OperatingSystem::Windows(os) => {
os.to_string()
}
}
}
}
impl Windows {
pub fn parse(label: &str) -> Result<Windows, String> {
let windows = windows::Windows::try_from(label)?;
Ok(Windows(windows))
}
pub fn vendor(&self) -> String {
self.0.vendor()
}
pub fn product(&self) -> String {
self.0.product()
}
pub fn to_string(&self) -> Vec<String> {
self.0.to_string()
}
}
impl TryFrom<&str> for OperatingSystem {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if let Ok(windows) = windows::Windows::try_from(value) {
Ok(OperatingSystem::Windows(Windows(windows)))
} else {
Err(format!("{} \"{}\"", ERR_UNKNOWN_OS, value))
}
}
}