Skip to main content

Module power

Module power 

Source
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§

BatteryState
What a battery is doing.

Functions§

batteries
Every system battery separately, in the order the OS lists them.
battery
The system battery, several combined; None when there is none.
has_battery
Whether the machine has a system battery. Cached.
on_ac
Whether the machine runs on mains power; None when it cannot be told, which is the answer on a desktop with no power information.