Expand description
Battery status reader.
Provides a platform-abstracted API for reading battery state. On Linux,
LinuxSysfsReader walks /sys/class/power_supply/ for the first
Battery-typed entry and reads capacity, status, energy_now,
power_now (or charge_now / current_now as fallback).
Non-Linux targets get UnsupportedReader which always returns
BatteryError::Unsupported. default_reader picks the right
implementation for the current platform.
§Example
use krypt_core::battery::default_reader;
let reader = default_reader();
match reader.read() {
Ok(r) => println!("{}% ({})", r.percent, r.status),
Err(e) => eprintln!("battery error: {e}"),
}Structs§
- Battery
Reading - A single battery reading.
- Linux
Sysfs Reader - Reads battery state from the Linux sysfs power-supply interface.
- Mock
Battery Reader - A mock
BatteryReaderthat returns a fixed result. - Unsupported
Reader - Battery reader for platforms where sysfs is unavailable.
Enums§
- Battery
Error - Errors that can occur while reading battery state.
- Battery
Status - Battery charge/discharge status.
Traits§
- Battery
Reader - Abstraction over battery hardware.
Functions§
- default_
reader - Return the best
BatteryReaderfor the current platform.