• Stars
    star
    334
  • Rank 126,264 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

battery

Latest Version Latest Version Build Status Minimum rustc version Apache 2.0 OR MIT licensed Backers on Open Collective Sponsors on Open Collective

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

Table of contents

Overview

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.

Install

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

Add the following line into a Cargo.toml:

[dependencies]
battery = "0.7.8"

Examples

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());
        println!("");
    }

    Ok(())
}

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

FFI bindings

Experimental battery-ffi crate provides the FFI bindings to the battery crate, so it can be used with other languages, such as C, Python or NodeJS.

Check its README and documentation for details.

Users

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!

battop

battop is an interactive viewer, similar to top, htop and other *top utilities, but about the batteries installed in your notebook.
It is using the battery crate API to show the batteries information in your terminal.

starship

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!

License

Licensed under either of Apache License 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Donations

If you appreciate my work and want to support me, you can do it here or support this project at Open Collective.

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

More Repositories

1

rust-battop

Interactive batteries viewer
Rust
405
star
2

unbound-telemetry

Prometheus exporter for Unbound DNS resolver
Rust
84
star
3

hostname

Cross-platform hostname functions in Rust
Rust
62
star
4

rust-claim

Assertion macros toolkit for Rust
Rust
61
star
5

python-wargaming

Pure-pythonic client library for Wargaming API
Python
27
star
6

python-opus

Is not maintained, sorry
Python
26
star
7

python-2gis

A Python library for accessing the 2gis API
Python
20
star
8

rust-imghdr

Library that determines the type of image contained in a file or byte stream
Rust
18
star
9

actix-httpbin

httpbin.org clone with Rust and actix-web
Rust
18
star
10

tornado-zmq-sockjs-example

Example of a application, which uses Tornado web-server for backend side, SockJS for client communications and ØMQ for inner communications.
Python
13
star
11

rust-icmp

Rust ICMP socket, intended to be similar to std TCP/UDP sockets in future
Rust
10
star
12

hid-magicmouse2

C
8
star
13

tokio-memcache

Rust+tokio memcache client. WIP
Rust
8
star
14

python-quirc

Python ctypes interface for QR code decoding library `libquirc`
Python
7
star
15

rust-macaddr

Primitive types for MAC addresses in Rust
Rust
5
star
16

fizz

C-based clone of the https://github.com/twitter/snowflake/. For studying purposes only.
C
5
star
17

rust-flake

Rust library for unique ID generation
Rust
2
star
18

rust-pgcopy

Rust encoder for PostgreSQL COPY WITH BINARY format
Rust
2
star
19

mhundwa

Бот-архивариус для авто-подлепры
Python
2
star
20

o_O

Python package names just for lulz
Python
1
star
21

python-aio2gis

asyncio-powered 2gis library for Python
Python
1
star
22

wiki-anon-edits-converter

Fast & furious wikipedia dump converter
C
1
star
23

link-unwrapper

Tornado server for a short links unwrapping
Python
1
star
24

random-imgur

Python
1
star
25

twitter-presentation

@svartalf/geekfest-twitter-stream rebranding.
Python
1
star
26

page-chat

Leave your message at the any place of page.
JavaScript
1
star
27

rust-memcache-proto

Memcache binary protocol implementation for Rust
Rust
1
star
28

xmpp-log

Simple XMPP MUC logger
Python
1
star