Trait libmacchina::traits::GeneralReadout [−][src]
pub trait GeneralReadout {
Show 20 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 local_ip(
&self,
interface: Option<String>
) -> 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<(AdjustedByte, AdjustedByte), 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;
pub struct MacOSGeneralReadout;
impl GeneralReadout for MacOSGeneralReadout {
fn new() -> Self {
MacOSGeneralReadout {}
}
fn username(&self) -> Result<String, ReadoutError> {
//let username = NSUserName();
Ok(String::from("johndoe"))
}
// Implement other trait functions...
}
Required methods
Provided 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
This function should return the user’s local ip address of the specified interface.
e.g. 192.168.1.11
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<(AdjustedByte, AdjustedByte), ReadoutError>
fn disk_space(&self) -> Result<(AdjustedByte, AdjustedByte), ReadoutError>
This function should return the used disk space in a human-readable and desirable format.
e.g. ‘1.2TB / 2TB’