CpuFreq

Trait CpuFreq 

Source
pub trait CpuFreq {
    const CPUFREQ_PATH: &'static str;

    // Provided methods
    fn read_file(fname: &str) -> Result<String, Error> { ... }
    fn write_file(fname: &str, data: &str) -> Result<(), Error> { ... }
    fn get_ranges(fname: &str) -> Result<Vec<usize>, Error> { ... }
    fn get_variable<T>(id: usize, var: &str) -> Result<T, Box<dyn Error>>
       where T: FromStr,
             T::Err: Error + 'static { ... }
    fn set_variable(id: usize, var: &str, data: &str) -> Result<(), Error> { ... }
    fn get_variable_all<T>(
        var: &str,
    ) -> Result<HashMap<usize, T>, Box<dyn Error>>
       where T: FromStr,
             T::Err: Error + 'static { ... }
    fn set_variable_all(var: &str, data: &str) -> Result<(), Error> { ... }
}
Expand description

Base cpufreq functionality for reading and writing on cpu variables

Required Associated Constants§

Source

const CPUFREQ_PATH: &'static str

Provided Methods§

Source

fn read_file(fname: &str) -> Result<String, Error>

Read file on CPUFREQ_PATH

§Panics

Panics if the content of the file is not utf8 encoded

Source

fn write_file(fname: &str, data: &str) -> Result<(), Error>

Write to file on CPUFREQ_PATH

Source

fn get_ranges(fname: &str) -> Result<Vec<usize>, Error>

Read and parse cpufreq ranges, example: 0,4,6-12,18 -> [0,4,6,7,8,9,10,12,18]

§Panics

Panics if values cannot be parsed to usize

Source

fn get_variable<T>(id: usize, var: &str) -> Result<T, Box<dyn Error>>
where T: FromStr, T::Err: Error + 'static,

Read a specific variable and parse to T

Source

fn set_variable(id: usize, var: &str, data: &str) -> Result<(), Error>

Sets a specific variable

Source

fn get_variable_all<T>(var: &str) -> Result<HashMap<usize, T>, Box<dyn Error>>
where T: FromStr, T::Err: Error + 'static,

Get variables for all online cpus

Source

fn set_variable_all(var: &str, data: &str) -> Result<(), Error>

Set variables for all online cpus

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl CpuFreq for CPU

Source§

const CPUFREQ_PATH: &'static str = "/sys/devices/system/cpu/"