Trait libmacchina::traits::GeneralReadout
source · pub trait GeneralReadout {
Show 20 methods
// Required methods
fn new() -> Self;
fn backlight(&self) -> Result<usize, ReadoutError>;
fn resolution(&self) -> Result<String, ReadoutError>;
fn username(&self) -> Result<String, ReadoutError>;
fn hostname(&self) -> Result<String, ReadoutError>;
fn distribution(&self) -> Result<String, ReadoutError>;
fn desktop_environment(&self) -> Result<String, ReadoutError>;
fn session(&self) -> Result<String, ReadoutError>;
fn window_manager(&self) -> Result<String, ReadoutError>;
fn terminal(&self) -> Result<String, ReadoutError>;
fn shell(
&self,
_shorthand: ShellFormat,
kind: ShellKind
) -> Result<String, ReadoutError>;
fn cpu_model_name(&self) -> Result<String, ReadoutError>;
fn cpu_usage(&self) -> Result<usize, ReadoutError>;
fn cpu_physical_cores(&self) -> Result<usize, ReadoutError>;
fn cpu_cores(&self) -> Result<usize, ReadoutError>;
fn uptime(&self) -> Result<usize, ReadoutError>;
fn machine(&self) -> Result<String, ReadoutError>;
fn os_name(&self) -> Result<String, ReadoutError>;
fn disk_space(&self) -> Result<(u64, u64), ReadoutError>;
fn gpus(&self) -> Result<Vec<String>, ReadoutError>;
}
Expand description
This trait provides the interface for implementing functionality used for querying general information about the running operating system and current user.
§Example
use libmacchina::traits::GeneralReadout;
use libmacchina::traits::ReadoutError;
use libmacchina::traits::ShellFormat;
use libmacchina::traits::ShellKind;
pub struct MacOSGeneralReadout;
impl GeneralReadout for MacOSGeneralReadout {
fn new() -> Self {
MacOSGeneralReadout {}
}
fn backlight(&self) -> Result<usize, ReadoutError> {
Ok(100) // Brightness is at its maximum
}
fn resolution(&self) -> Result<String, ReadoutError> {
Ok("1920x1080".to_string())
}
fn username(&self) -> Result<String, ReadoutError> {
//let username = NSUserName();
Ok(String::from("johndoe"))
}
fn hostname(&self) -> Result<String, ReadoutError> {
Ok("supercomputer".to_string())
}
fn distribution(&self) -> Result<String, ReadoutError> {
Ok("Arch Linux".to_string())
}
fn desktop_environment(&self) -> Result<String, ReadoutError> {
Ok("Plasma".to_string())
}
fn session(&self) -> Result<String, ReadoutError> {
Ok("Wayland".to_string())
}
fn window_manager(&self) -> Result<String, ReadoutError> {
Ok("KWin".to_string())
}
fn terminal(&self) -> Result<String, ReadoutError> {
Ok("kitty".to_string())
}
fn shell(&self, _shorthand: ShellFormat, kind: ShellKind) -> Result<String, ReadoutError> {
Ok("bash".to_string())
}
fn cpu_model_name(&self) -> Result<String, ReadoutError> {
Ok("Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz".to_string())
}
fn cpu_usage(&self) -> Result<usize, ReadoutError> {
Ok(20) //20% CPU usage
}
fn cpu_physical_cores(&self) -> Result<usize, ReadoutError> {
Ok(4)
}
fn cpu_cores(&self) -> Result<usize, ReadoutError> {
Ok(8)
}
fn uptime(&self) -> Result<usize, ReadoutError> {
Ok(24 * 60 * 60) //1 day
}
fn machine(&self) -> Result<String, ReadoutError> {
Ok("MacBookPro11,5".to_string())
}
fn os_name(&self) -> Result<String, ReadoutError> {
Ok("macOS 11.2.2 Big Sur".to_string())
}
fn disk_space(&self) -> Result<(u64, u64), ReadoutError> {
Ok((50000000,1000000000)) // Used / Total
}
fn gpus(&self) -> Result<Vec<String>, ReadoutError> {
// Get gpu(s) from list of connected pci devices
Ok(vec!(String::from("gpu1"), String::from("gpu2"))) // Return gpu sub-device names
}
}
Required Methods§
sourcefn backlight(&self) -> Result<usize, ReadoutError>
fn backlight(&self) -> Result<usize, ReadoutError>
This function should return the backlight (brightness) value of the machine.
e.g. 100
sourcefn resolution(&self) -> Result<String, ReadoutError>
fn resolution(&self) -> Result<String, ReadoutError>
This function should return the display resolution of the machine.
_e.g. 1920x1080
sourcefn username(&self) -> Result<String, ReadoutError>
fn username(&self) -> Result<String, ReadoutError>
This function should return the username of the currently logged on user.
e.g. johndoe
sourcefn hostname(&self) -> Result<String, ReadoutError>
fn hostname(&self) -> Result<String, ReadoutError>
This function should return the hostname of the host’s computer.
e.g. supercomputer
sourcefn distribution(&self) -> Result<String, ReadoutError>
fn distribution(&self) -> Result<String, ReadoutError>
This function should return the name of the distribution of the operating system.
e.g. Arch Linux
sourcefn desktop_environment(&self) -> Result<String, ReadoutError>
fn desktop_environment(&self) -> Result<String, ReadoutError>
This function should return the name of the used desktop environment.
e.g. Plasma
sourcefn session(&self) -> Result<String, ReadoutError>
fn session(&self) -> Result<String, ReadoutError>
This function should return the type of session that’s in use.
e.g. Wayland
sourcefn window_manager(&self) -> Result<String, ReadoutError>
fn window_manager(&self) -> Result<String, ReadoutError>
This function should return the name of the used window manager.
e.g. KWin
sourcefn terminal(&self) -> Result<String, ReadoutError>
fn terminal(&self) -> Result<String, ReadoutError>
This function should return the name of the used terminal emulator.
e.g. kitty
sourcefn shell(
&self,
_shorthand: ShellFormat,
kind: ShellKind
) -> Result<String, ReadoutError>
fn shell( &self, _shorthand: ShellFormat, kind: ShellKind ) -> Result<String, ReadoutError>
This function should return the currently running shell depending on the _shorthand
value.
- If
_shorthand
isShellFormat::Relative
the basename of the shell will be returned.
e.g. bash, zsh, etc.
- If
_shorthand
isShellFormat::Absolute
the absolute path of the shell will be returned.
e.g. /bin/bash, /bin/zsh, etc.
sourcefn cpu_model_name(&self) -> Result<String, ReadoutError>
fn cpu_model_name(&self) -> Result<String, ReadoutError>
This function should return the model name of the CPU
e.g. Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
sourcefn cpu_usage(&self) -> Result<usize, ReadoutError>
fn cpu_usage(&self) -> Result<usize, ReadoutError>
This function should return the average CPU usage over the last minute.
sourcefn cpu_physical_cores(&self) -> Result<usize, ReadoutError>
fn cpu_physical_cores(&self) -> Result<usize, ReadoutError>
This function should return the number of physical cores of the host’s processor.
sourcefn cpu_cores(&self) -> Result<usize, ReadoutError>
fn cpu_cores(&self) -> Result<usize, ReadoutError>
This function should return the number of logical cores of the host’s processor.
sourcefn uptime(&self) -> Result<usize, ReadoutError>
fn uptime(&self) -> Result<usize, ReadoutError>
This function should return the uptime of the OS in seconds.
sourcefn machine(&self) -> Result<String, ReadoutError>
fn machine(&self) -> Result<String, ReadoutError>
This function should return the name of the physical machine.
e.g. MacBookPro11,5
sourcefn os_name(&self) -> Result<String, ReadoutError>
fn os_name(&self) -> Result<String, ReadoutError>
This function should return the name of the OS in a pretty format.
e.g. macOS 11.2.2 Big Sur
sourcefn disk_space(&self) -> Result<(u64, u64), ReadoutError>
fn disk_space(&self) -> Result<(u64, u64), ReadoutError>
This function should return a tuple with the number values representing used and total bytes of disk space.
e.g. ‘(50000000, 1000000000)’