mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-28 01:17:45 +00:00
battery: use a reference to SupportedBattery
instead of clones
This commit is contained in:
parent
7c34ef5aa0
commit
705fc6c46d
1 changed files with 6 additions and 6 deletions
|
@ -43,9 +43,9 @@ const THRESHOLD_PATTERNS: &[ThresholdPathPattern] = &[
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Represents a battery that supports charge threshold control
|
/// Represents a battery that supports charge threshold control
|
||||||
pub struct SupportedBattery {
|
pub struct SupportedBattery<'a> {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub pattern: ThresholdPathPattern,
|
pub pattern: &'a ThresholdPathPattern,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ pub fn set_battery_charge_thresholds(start_threshold: u8, stop_threshold: u8) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds all batteries in the system that support threshold control
|
/// Finds all batteries in the system that support threshold control
|
||||||
fn find_supported_batteries(power_supply_path: &Path) -> Result<Vec<SupportedBattery>> {
|
fn find_supported_batteries(power_supply_path: &Path) -> Result<Vec<SupportedBattery<'static>>> {
|
||||||
let entries = fs::read_dir(power_supply_path).map_err(|e| {
|
let entries = fs::read_dir(power_supply_path).map_err(|e| {
|
||||||
if e.kind() == io::ErrorKind::PermissionDenied {
|
if e.kind() == io::ErrorKind::PermissionDenied {
|
||||||
ControlError::PermissionDenied(format!(
|
ControlError::PermissionDenied(format!(
|
||||||
|
@ -154,14 +154,14 @@ fn write_sysfs_value(path: impl AsRef<Path>, value: &str) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Identifies if a battery supports threshold control and which pattern it uses
|
/// Identifies if a battery supports threshold control and which pattern it uses
|
||||||
fn find_battery_with_threshold_support(ps_path: &Path) -> Option<SupportedBattery> {
|
fn find_battery_with_threshold_support(ps_path: &Path) -> Option<SupportedBattery<'static>> {
|
||||||
for pattern in THRESHOLD_PATTERNS {
|
for pattern in THRESHOLD_PATTERNS {
|
||||||
let start_threshold_path = ps_path.join(pattern.start_path);
|
let start_threshold_path = ps_path.join(pattern.start_path);
|
||||||
let stop_threshold_path = ps_path.join(pattern.stop_path);
|
let stop_threshold_path = ps_path.join(pattern.stop_path);
|
||||||
if start_threshold_path.exists() && stop_threshold_path.exists() {
|
if start_threshold_path.exists() && stop_threshold_path.exists() {
|
||||||
return Some(SupportedBattery {
|
return Some(SupportedBattery {
|
||||||
name: ps_path.file_name()?.to_string_lossy().to_string(),
|
name: ps_path.file_name()?.to_string_lossy().to_string(),
|
||||||
pattern: pattern.clone(),
|
pattern,
|
||||||
path: ps_path.to_path_buf(),
|
path: ps_path.to_path_buf(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ fn find_battery_with_threshold_support(ps_path: &Path) -> Option<SupportedBatter
|
||||||
|
|
||||||
/// Applies the threshold settings to all supported batteries
|
/// Applies the threshold settings to all supported batteries
|
||||||
fn apply_thresholds_to_batteries(
|
fn apply_thresholds_to_batteries(
|
||||||
batteries: &[SupportedBattery],
|
batteries: &[SupportedBattery<'_>],
|
||||||
start_threshold: u8,
|
start_threshold: u8,
|
||||||
stop_threshold: u8,
|
stop_threshold: u8,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue