Trait libmacchina::traits::GeneralReadout [−][src]
pub trait GeneralReadout {
Show 19 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<(u128, u128), 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<(u128, u128), ReadoutError> {
Ok((50000000,1000000000)) // Used / Total
}
}
Required methods
fn 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
fn resolution(&self) -> Result<String, ReadoutError>
fn resolution(&self) -> Result<String, ReadoutError>
This function should return the display resolution of the machine.
_e.g. 1920x1080
fn 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
fn 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
fn 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
fn 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
fn 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
fn 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
fn 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
fn 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.
fn 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
fn 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.
fn 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.
fn 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.
fn uptime(&self) -> Result<usize, ReadoutError>
fn uptime(&self) -> Result<usize, ReadoutError>
This function should return the uptime of the OS in seconds.
fn 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
fn 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
fn disk_space(&self) -> Result<(u128, u128), ReadoutError>
fn disk_space(&self) -> Result<(u128, u128), ReadoutError>
This function should return the used disk space in a human-readable and desirable format.
e.g. ‘1.2TB / 2TB’