desktop/
lib.rs

1mod os_name;
2mod arch;
3mod environment;
4
5use crate::os_name::ret_os_name;
6use crate::arch::ret_arch;
7use crate::environment::ret_environment;
8
9/// The main struct of the library, contains the OS information
10#[derive(Debug)]
11pub struct Desktop {
12    os_name: &'static str,
13    arch: &'static str,
14    environment: &'static str,
15}
16
17impl Desktop {
18    /// Returns a `Desktop` struct containing your machine info
19    pub fn get() -> Self {
20        Desktop {
21            os_name: ret_os_name(),
22            arch: ret_arch(),
23            environment: ret_environment(),
24        }
25    }
26
27    /// Retrieves the name of the OS
28    pub fn os_name(&self) -> &'static str {
29        self.os_name
30    }
31
32    /// Retrieves the architecture of the OS
33    pub fn arch(&self) -> &'static str {
34        self.arch
35    }
36
37    /// Retrieves the desktop environment of the OS (Linux only)
38    ///
39    /// Otherwise, if it's not Linux or it was not able to detect the desktop environment (`option_env!` returns `Err`),
40    ///
41    /// it will return the name of the OS
42    pub fn environment(&self) -> &'static str {
43        self.environment
44    }
45}
46
47#[test]
48fn test_struct() {
49    let d = Desktop::get();
50    println!("{:#?}", d);
51}