Expand description
The system battery and mains power.
Only batteries that power the machine count: wireless mice, keyboards, and headsets report batteries too and are left out (E-81). Several internal batteries are combined by energy, not by averaging percentages (E-82).
use sys_lib as sys;
if let Some(b) = sys::power::battery()? {
println!("battery {} {:?}, empty in {:?}", b.charge, b.state, b.time_to_empty);
}
if sys::power::on_ac()? == Some(false) {
// on battery: back off background work
}Structs§
- Battery
- A battery, or several combined.
Enums§
- Battery
State - What a battery is doing.
Functions§
- batteries
- Every system battery separately, in the order the OS lists them.
- battery
- The system battery, several combined;
Nonewhen there is none. - has_
battery - Whether the machine has a system battery. Cached.
- on_ac
- Whether the machine runs on mains power;
Nonewhen it cannot be told, which is the answer on a desktop with no power information.