pub trait KernelReadout {
    // Required methods
    fn new() -> Self;
    fn os_release(&self) -> Result<String, ReadoutError>;
    fn os_type(&self) -> Result<String, ReadoutError>;

    // Provided method
    fn pretty_kernel(&self) -> Result<String, ReadoutError> { ... }
}
Expand description

This trait is used for implementing common functions for reading kernel properties, such as kernel name and version.

§Example

use libmacchina::traits::KernelReadout;
use libmacchina::traits::ReadoutError;

pub struct MacOSKernelReadout;

impl KernelReadout for MacOSKernelReadout {
    fn new() -> Self {
        MacOSKernelReadout {}
    }

    fn os_release(&self) -> Result<String, ReadoutError> {
        // Get kernel version
        Ok(String::from("20.0.1"))
    }

    fn os_type(&self) -> Result<String, ReadoutError> {
        // Get kernel name
        Ok(String::from("Darwin"))
    }
}

Required Methods§

source

fn new() -> Self

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

source

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

This function should return the version of the kernel (e. g. 20.3.0 on macOS for Darwin).

source

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

This function should return the kernel name as a string (e. g. Darwin on macOS).

Provided Methods§

source

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

This function is used for getting the kernel name and version in a pretty format.

Object Safety§

This trait is not object safe.

Implementors§