use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Device {
pub(crate) os: Os,
pub(crate) system: System,
}
impl Default for Device {
fn default() -> Self {
Device {
os: Os::default(),
system: System::unknown(),
}
}
}
impl Device {
pub fn set_system(mut self, system: System) -> Self {
self.system = system;
self
}
pub fn set_os(mut self, os: Os) -> Self {
self.os = os;
self
}
}
impl System {
#[allow(missing_docs)]
pub fn unknown() -> Self {
Self {
name: "Unknown".to_string(),
build: "Unknown".to_string(),
version: "Unknown".to_string(),
lang: "Unknown".to_string(),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Os {
#[allow(missing_docs)]
pub platform: String,
#[allow(missing_docs)]
pub name: String,
#[allow(missing_docs)]
pub version: String,
}
impl Default for Os {
fn default() -> Self {
let os = os_info::get();
Os {
version: os.version().to_string(),
name: os.os_type().to_string(),
platform: os.to_string(),
}
}
}
impl Os {
#[allow(missing_docs)]
pub fn unknown() -> Self {
Self {
version: "Unknown".to_string(),
name: "Unknown".to_string(),
platform: "Unknown".to_string(),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct System {
#[allow(missing_docs)]
pub name: String,
#[allow(missing_docs)]
pub version: String,
#[allow(missing_docs)]
pub build: String,
#[allow(missing_docs)]
pub lang: String,
}
impl Default for System {
fn default() -> Self {
System {
name: env!("CARGO_PKG_NAME").to_string(),
build: "rust".to_string(),
version: env!("CARGO_PKG_VERSION").to_string(),
lang: "rust".to_string(),
}
}
}