Skip to main content

Crate day_part_battery

Crate day_part_battery 

Source
Expand description

day-part-battery — a HEADLESS cross-platform battery-status API. No UI; any Rust code can depend on this crate and call status to read the device battery through the platform’s NATIVE API.

if let Some(b) = day_part_battery::status() {
    println!("{:?} at {:?}%", b.state, b.percent());
}

Platform selection is purely #[cfg(target_os)]/#[cfg(target_env)] (a battery is an OS concern, not a widget-toolkit one): macOS uses IOKit, iOS UIDevice, Windows GetSystemPowerStatus, Linux /sys/class/power_supply, HarmonyOS the native libohbattery_info.so, and Android BatteryManager (via a Java shim staged by day build). Platforms without a battery API — or devices with no battery — return None.

Structs§

BatteryStatus
A snapshot of the device battery.

Enums§

BatteryState
The battery’s charging state.

Functions§

status
Read the current battery status via the platform’s native API. Returns None when there is no battery API for the platform, or the device has no battery.
Day API ↩ Guides· daybrite.dev