Skip to content

Commit

Permalink
Modify list_cpus() to return a result and adjust the functions
Browse files Browse the repository at this point in the history
which depend on them to return result.
  • Loading branch information
Camerooooon committed Feb 22, 2024
1 parent cd84ee0 commit 5979b6c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ pub fn check_available_governors() -> Result<Vec<String>, Error> {
}

/// Get all the cpus (cores), returns cpus from 0 to the (amount of cores -1) the machine has
#[once]
pub fn list_cpus() -> Vec<CPU> {
pub fn list_cpus() -> Result<Vec<CPU>, Error> {
let mut cpus: Vec<String> = Vec::<String>::new();

// Get each item in the cpu directory
Expand Down Expand Up @@ -228,30 +227,30 @@ pub fn list_cpus() -> Vec<CPU> {
gov: "Unknown".to_string(),
};

new.init_cpu().unwrap();
new.init_cpu()?;

new.update().unwrap();
new.update()?;

to_return.push(new)
}

to_return.sort_by(|a, b| a.number.cmp(&b.number));
to_return
Ok(to_return)
}

/// Get a vector of speeds reported from each cpu from list_cpus
pub fn list_cpu_speeds() -> Vec<i32> {
list_cpus().into_iter().map(|x| x.cur_freq).collect()
pub fn list_cpu_speeds() -> Result<Vec<i32>, Error> {
Ok(list_cpus()?.into_iter().map(|x| x.cur_freq).collect())
}

/// Get a vector of temperatures reported from each cpu from list_cpus
pub fn list_cpu_temp() -> Vec<i32> {
list_cpus().into_iter().map(|x| x.cur_temp).collect()
pub fn list_cpu_temp() -> Result<Vec<i32>, Error> {
Ok(list_cpus()?.into_iter().map(|x| x.cur_temp).collect())
}

/// Get a vector of the governors that the cpus from list_cpus
pub fn list_cpu_governors() -> Vec<String> {
list_cpus().into_iter().map(|x| x.gov).collect()
pub fn list_cpu_governors() -> Result<Vec<String>, Error> {
Ok(list_cpus()?.into_iter().map(|x| x.gov).collect())
}

pub fn read_int(path: &str) -> Result<i32, Error> {
Expand Down

0 comments on commit 5979b6c

Please sign in to comment.