JakeRoggenbuck / auto-clock-speed

A utility to check stats about your CPU, and auto regulate clock speeds to help with either performance or battery life.
https://autoclockspeed.org
MIT License
33 stars 9 forks source link

Move the paths from each sub_path in write_value method to enum #413

Open JakeRoggenbuck opened 2 years ago

JakeRoggenbuck commented 2 years ago

Move the paths hard coded in the match from CPU::write_value as seen here

fn write_value(&mut self, value: WritableValue) -> Result<(), Error> {
    let sub_path: &str;
    let to_write: String;

    match value {
        WritableValue::Max => {
            sub_path = "cpufreq/scaling_max_freq";
            to_write = self.max_freq.to_string();
        }
        WritableValue::Min => {
            sub_path = "cpufreq/scaling_min_freq";
            to_write = self.min_freq.to_string();
        }
        WritableValue::Gov => {
            sub_path = "cpufreq/scaling_governor";
            to_write = self.gov.to_string();
        }
    }

// --- snip ---
}

Move to the enum that is matched

#[derive(PartialEq, Eq)]
pub enum WritableValue {
    Min,
    Max,
    Gov,
}