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§

source

fn new() -> Self

Creates a new instance of the structure which implements this trait.

source

fn backlight(&self) -> Result<usize, ReadoutError>

This function should return the backlight (brightness) value of the machine.

e.g. 100

source

fn resolution(&self) -> Result<String, ReadoutError>

This function should return the display resolution of the machine.

_e.g. 1920x1080

source

fn username(&self) -> Result<String, ReadoutError>

This function should return the username of the currently logged on user.

e.g. johndoe

source

fn hostname(&self) -> Result<String, ReadoutError>

This function should return the hostname of the host’s computer.

e.g. supercomputer

source

fn distribution(&self) -> Result<String, ReadoutError>

This function should return the name of the distribution of the operating system.

e.g. Arch Linux

source

fn desktop_environment(&self) -> Result<String, ReadoutError>

This function should return the name of the used desktop environment.

e.g. Plasma

source

fn session(&self) -> Result<String, ReadoutError>

This function should return the type of session that’s in use.

e.g. Wayland

source

fn window_manager(&self) -> Result<String, ReadoutError>

This function should return the name of the used window manager.

e.g. KWin

source

fn terminal(&self) -> Result<String, ReadoutError>

This function should return the name of the used terminal emulator.

e.g. kitty

source

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 is ShellFormat::Relative the basename of the shell will be returned.

e.g. bash, zsh, etc.

  • If _shorthand is ShellFormat::Absolute the absolute path of the shell will be returned.

e.g. /bin/bash, /bin/zsh, etc.

source

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

source

fn cpu_usage(&self) -> Result<usize, ReadoutError>

This function should return the average CPU usage over the last minute.

source

fn cpu_physical_cores(&self) -> Result<usize, ReadoutError>

This function should return the number of physical cores of the host’s processor.

source

fn cpu_cores(&self) -> Result<usize, ReadoutError>

This function should return the number of logical cores of the host’s processor.

source

fn uptime(&self) -> Result<usize, ReadoutError>

This function should return the uptime of the OS in seconds.

source

fn machine(&self) -> Result<String, ReadoutError>

This function should return the name of the physical machine.

e.g. MacBookPro11,5

source

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

source

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)’

source

fn gpus(&self) -> Result<Vec<String>, ReadoutError>

This function should return the device names of any GPU(s) connected to the host machine.

Object Safety§

This trait is not object safe.

Implementors§