Skip to content

Commit 325486c

Browse files
committed
Use match and if let to avoid unwrapping
Fix new clippy warnings: https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#unnecessary_unwrap Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent e6b839e commit 325486c

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

framework_lib/src/commandline/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
12631263
}
12641264

12651265
// Must be run before any application code to set the config
1266-
if args.pd_addrs.is_some() && args.pd_ports.is_some() {
1267-
let platform = Platform::GenericFramework(args.pd_addrs.unwrap(), args.pd_ports.unwrap());
1266+
if let (Some(pd_addrs), Some(pd_ports)) = (args.pd_addrs, args.pd_ports) {
1267+
let platform = Platform::GenericFramework(pd_addrs, pd_ports);
12681268
Config::set(platform);
12691269
}
12701270

framework_lib/src/power.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,14 @@ fn print_battery_information(power_info: &PowerInfo) {
616616
pub fn check_update_ready(power_info: &PowerInfo) -> bool {
617617
// Checking if battery/AC conditions are enough for FW update
618618
// Either standalone mode or AC+20% charge
619-
if power_info.battery.is_none()
620-
|| (power_info.ac_present && power_info.battery.as_ref().unwrap().charge_percentage > 20)
621-
{
622-
true
623-
} else {
624-
println!("Please plug in AC. If the battery is connected, charge it to at least 20% before proceeding.");
625-
println!(
626-
"Current charge is: {}%",
627-
power_info.battery.as_ref().unwrap().charge_percentage
628-
);
629-
false
619+
match &power_info.battery {
620+
None => true,
621+
Some(battery) if power_info.ac_present && battery.charge_percentage > 20 => true,
622+
Some(battery) => {
623+
println!("Please plug in AC. If the battery is connected, charge it to at least 20% before proceeding.");
624+
println!("Current charge is: {}%", battery.charge_percentage);
625+
false
626+
}
630627
}
631628
}
632629

0 commit comments

Comments
 (0)