#battery #linux #macos #windows #freebsd


Cross-platform information about the notebook batteries

4 releases

0.8.2 Aug 5, 2023
0.8.1 Jun 8, 2023
0.8.0 Apr 12, 2023
0.7.9 Nov 9, 2021

#54 in Operating systems

Download history 4363/week @ 2023-08-11 4356/week @ 2023-08-18 5743/week @ 2023-08-25 4608/week @ 2023-09-01 4819/week @ 2023-09-08 5528/week @ 2023-09-15 4758/week @ 2023-09-22 4982/week @ 2023-09-29 4586/week @ 2023-10-06 4456/week @ 2023-10-13 4854/week @ 2023-10-20 4508/week @ 2023-10-27 4810/week @ 2023-11-03 4106/week @ 2023-11-10 3974/week @ 2023-11-17 2972/week @ 2023-11-24

16,536 downloads per month
Used in 5 crates

ISC license



Latest Version Latest Version Build Status Minimum rustc version ISC licensed

Rust crate providing cross-platform information about the notebook batteries.

Table of contents


battery provides a cross-platform unified API to a notebook batteries state.

Its main goal is to wrap the OS-specific interfaces, cover all the hacks and legacy cases and get the batteries information (such as state of charge, energy rate, voltage and temperature) as a typed values, recalculated as necessary to be returned as a SI measurement units.

Supported platforms

  • Linux 2.6.39+
  • MacOS 10.10+
  • iOS
  • Windows 7+
  • FreeBSD
  • DragonFlyBSD

Do note that iOS implementation uses IOKit bindings, your application might be automatically rejected by Apple based on that fact. Use it on your own risk.


As a prerequisite, battery crate requires at least Rustc version 1.63 or greater.

Add the following line into a Cargo.toml:

battery = "0.7.8"


fn main() -> Result<(), battery::Error> {
    let manager = battery::Manager::new()?;

    for (idx, maybe_battery) in manager.batteries()?.enumerate() {
        let battery = maybe_battery?;
        println!("Battery #{}:", idx);
        println!("Vendor: {:?}", battery.vendor());
        println!("Model: {:?}", battery.model());
        println!("State: {:?}", battery.state());
        println!("Time to full charge: {:?}", battery.time_to_full());


See the battery/examples/ folder in the repository for additional examples.


This an incomplete list of the battery crate users. If you are using it too, send me a message and I'll add your project here!


starship is a Rust port of the minimalistic, powerful, and extremely customizable prompt Spaceship ZSH.
It is using the battery crate to show the the current battery level and status in a shell prompt.

Here is what @matchai says:

I really appreciate how easily we were able to get your library up and running! Battery APIs were a headache for us in predecessors of this project 😅

And there is this tweet also!


~38K SLoC