svartalf / rust-battery

Rust crate providing cross-platform information about the notebook batteries.
https://crates.io/crates/battery
Apache License 2.0
354 stars 40 forks source link

Allow empty `FullyCharged` and `DesignCapacity` #93

Open horasal opened 2 years ago

horasal commented 2 years ago

On MacMini M1(or maybe all devices with macOS 12, I haven't tested on other macs), FullyCharged and DesignCapacity are missing. However, current both of them are required or PowerSource will throw an error. SourceCode e.g. the following error

[WARN] - (starship::modules::battery): Unable to access battery information:                                                             
FullyCharged

This pr makes PowerSource accepts empty FullyCharged and DesignCapacity. If they are missing, users will get a default value. (i.e. true for FullyCharged and Default::default() for DesignCapacity).