{"id":13496658,"url":"https://github.com/svartalf/rust-battery","last_synced_at":"2025-05-15T13:07:58.578Z","repository":{"id":43496242,"uuid":"169845876","full_name":"svartalf/rust-battery","owner":"svartalf","description":"Rust crate providing cross-platform information about the notebook batteries.","archived":false,"fork":false,"pushed_at":"2023-08-01T02:43:42.000Z","size":254,"stargazers_count":367,"open_issues_count":25,"forks_count":41,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-10T15:40:49.505Z","etag":null,"topics":["battery","battery-information","dragonflybsd","freebsd","linux","macos","rust","rust-crate","windows"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/battery","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/svartalf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"open_collective":"rust-battery","liberapay":"svartalf","patreon":"svartalf","custom":["https://svartalf.info/donate/","https://www.buymeacoffee.com/svartalf"]}},"created_at":"2019-02-09T08:16:03.000Z","updated_at":"2025-05-05T20:59:30.000Z","dependencies_parsed_at":"2022-07-15T06:47:17.324Z","dependency_job_id":null,"html_url":"https://github.com/svartalf/rust-battery","commit_stats":{"total_commits":86,"total_committers":10,"mean_commits":8.6,"dds":"0.19767441860465118","last_synced_commit":"20233871e16b0e7083281df560875110a0cac93b"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svartalf%2Frust-battery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svartalf%2Frust-battery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svartalf%2Frust-battery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svartalf%2Frust-battery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svartalf","download_url":"https://codeload.github.com/svartalf/rust-battery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254265722,"owners_count":22041973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["battery","battery-information","dragonflybsd","freebsd","linux","macos","rust","rust-crate","windows"],"created_at":"2024-07-31T19:01:55.363Z","updated_at":"2025-05-15T13:07:58.510Z","avatar_url":"https://github.com/svartalf.png","language":"Rust","funding_links":["https://opencollective.com/rust-battery","https://liberapay.com/svartalf","https://patreon.com/svartalf","https://svartalf.info/donate/","https://www.buymeacoffee.com/svartalf"],"categories":["Rust","Libraries"],"sub_categories":["Platform specific"],"readme":"# battery\n\n[![Latest Version](https://img.shields.io/crates/v/battery.svg)](https://crates.io/crates/battery)\n[![Latest Version](https://docs.rs/battery/badge.svg)](https://docs.rs/battery)\n[![Build Status](https://github.com/svartalf/rust-battery/workflows/Continuous%20integration/badge.svg)](https://github.com/svartalf/rust-battery/actions?workflow=Continuous+integration)\n![Minimum rustc version](https://img.shields.io/badge/rustc-1.36+-yellow.svg)\n![Apache 2.0 OR MIT licensed](https://img.shields.io/badge/license-Apache2.0%2FMIT-blue.svg)\n[![Backers on Open Collective](https://opencollective.com/rust-battery/backers/badge.svg)](#backers)\n[![Sponsors on Open Collective](https://opencollective.com/rust-battery/sponsors/badge.svg)](#sponsors)\n\n\u003e Rust crate providing cross-platform information about the notebook batteries.\n\n## Table of contents\n\n * [Overview](#overview)\n * [Supported platforms](#supported-platforms)\n * [Install](#install)\n * [Examples](#examples)\n * [FFI bindings](#ffi-bindings)\n * [Users](#users)\n * [License](#license)\n * [Donations](#donations)\n * [Contributors](#contributors)\n * [Backers](#backers)\n * [Sponsors](#sponsors)\n\n## Overview\n\n`battery` provides a cross-platform unified API to a notebook batteries state.\n\nIts main goal is to wrap the OS-specific interfaces, cover all the hacks and legacy cases\nand get the batteries information (such as state of charge, energy rate, voltage and temperature)\nas a typed values, recalculated as necessary to be returned as a [SI measurement units](https://www.bipm.org/en/measurement-units/).\n\n## Supported platforms\n\n* Linux 2.6.39+\n* MacOS 10.10+\n* iOS\n* Windows 7+\n* FreeBSD\n* DragonFlyBSD\n\nDo note that iOS implementation uses IOKit bindings, your application\nmight be automatically rejected by Apple based on that fact. Use it on your own risk.\n\n## Install\n\nAs a prerequisite, `battery` crate requires at least Rustc version **1.36** or greater.\n\nAdd the following line into a `Cargo.toml`:\n\n```toml\n[dependencies]\nbattery = \"0.7.8\"\n```\n\n## Examples\n\n```rust\nfn main() -\u003e Result\u003c(), battery::Error\u003e {\n    let manager = battery::Manager::new()?;\n\n    for (idx, maybe_battery) in manager.batteries()?.enumerate() {\n        let battery = maybe_battery?;\n        println!(\"Battery #{}:\", idx);\n        println!(\"Vendor: {:?}\", battery.vendor());\n        println!(\"Model: {:?}\", battery.model());\n        println!(\"State: {:?}\", battery.state());\n        println!(\"Time to full charge: {:?}\", battery.time_to_full());\n        println!(\"\");\n    }\n\n    Ok(())\n}\n```\n\nSee the `battery/examples/` folder in the [repository](https://github.com/svartalf/rust-battery/blob/master/battery/examples/simple.rs)\nfor additional examples.\n\n## FFI bindings\n\nExperimental [battery-ffi](https://crates.io/crates/battery-ffi) crate provides the FFI bindings to the `battery` crate,\nso it can be used with other languages, such as C, Python or NodeJS.\n\nCheck its [README](https://github.com/svartalf/rust-battery/tree/master/battery-ffi)\nand [documentation](https://docs.rs/battery-ffi) for details.\n\n## Users\n\nThis an incomplete list of the `battery` crate users. If you are using it too,\nsend me a message and I'll add your project here!\n\n### battop\n\n[`battop`](https://github.com/svartalf/rust-battop) is an interactive viewer,\nsimilar to `top`, `htop` and other \\*top utilities, but about the batteries installed in your notebook.\\\nIt is using the `battery` crate API to show the batteries information in your terminal.\n\n### starship\n\n[`starship`](https://github.com/starship/starship) is a Rust port of the minimalistic, powerful,\nand extremely customizable prompt Spaceship ZSH.\\\nIt is using the `battery` crate to show the the current battery level and status in a shell prompt.\n\nHere is what [@matchai](https://github.com/matchai) says:\n\n\u003e I really appreciate how easily we were able to get your library up and running!\n\u003e Battery APIs were a headache for us in predecessors of this project 😅\n\nAnd there is [this tweet](https://twitter.com/matchai/status/1135906726392283136) also!\n\n## License\n\nLicensed under either of [Apache License 2.0](https://github.com/svartalf/rust-battery/blob/master/LICENSE-APACHE)\nor [MIT license](https://github.com/svartalf/rust-battery/blob/master/LICENSE-MIT) at your option.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you,\nas defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n## Donations\n\nIf you appreciate my work and want to support me, you can do it [here](https://svartalf.info/donate/) or\nsupport this project at [Open Collective](https://opencollective.com/rust-battery).\n\n## Contributors\n\nThis project exists thanks to all the people who contribute.\n\u003ca href=\"https://github.com/svartalf/rust-battery/graphs/contributors\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/contributors.svg?width=890\u0026button=false\" /\u003e\u003c/a\u003e\n\n## Backers\n\nThank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/rust-battery#backer)]\n\n\u003ca href=\"https://opencollective.com/rust-battery#backers\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/backers.svg?width=890\"\u003e\u003c/a\u003e\n\n## Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/rust-battery#sponsor)]\n\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/0/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/0/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/1/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/1/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/2/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/2/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/3/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/3/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/4/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/4/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/5/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/5/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/6/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/6/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/7/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/7/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/8/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/8/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/rust-battery/sponsor/9/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/rust-battery/sponsor/9/avatar.svg\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvartalf%2Frust-battery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvartalf%2Frust-battery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvartalf%2Frust-battery/lists"}