battery_ffi/lib.rs
1//! This crate provides C ABI interface for [battery](https://crates.io/crate/battery) crate.
2//!
3//! # Bindings generation
4//!
5//! Among library creation this crate generates `battery_ffi.h` file, enabled by default by `cbindgen` feature,
6//! which might be useful for automatic bindings generation or just with plain `C`/`C++` development.
7//!
8//! After build it will be located somewhere at `target/*/build/battery-ffi-*/out/`,
9//! depending on build profile (`debug`/`release`) and build hash.
10//!
11//! Disabling `cbindgen` feature might speed up compilation a little bit,
12//! especially if you don't need the header file.
13//!
14//! # Examples
15//!
16//! ```c
17//! #include "battery_ffi.h"
18//!
19//! void main() {
20//! Manager *manager = battery_manager_new();
21//! // .. handle `manager == NULL` here ..
22//! Batteries *iterator = battery_manager_iter(manager);
23//! // .. handle `iterator == NULL` here ..
24//! while (true) {
25//! Battery *battery = battery_iterator_next(iterator);
26//! // .. handle possible error here ..
27//! if (battery == NULL) {
28//! break;
29//! }
30//!
31//! // Use some `battery_get_*` functions here
32//!
33//! battery_free(battery);
34//! }
35//!
36//! battery_iterator_free(iterator);
37//! battery_manager_free(manager);
38//! }
39//! ```
40//!
41//! Also, check the `examples/` directory in the repository for examples with C and Python.
42
43#![doc(html_root_url = "https://docs.rs/battery-ffi/0.7.5")]
44#![allow(clippy::missing_safety_doc)]
45
46// cbindgen==0.8.0 fails to export typedefs for opaque pointers
47// from the battery crate, if this line is missing
48extern crate battery as battery_lib;
49
50mod battery;
51mod errors;
52mod iterator;
53mod manager;
54mod state;
55mod technology;
56
57/// Opaque struct representing battery manager.
58///
59/// End users should consider it as a some memory somewhere in the heap,
60/// and work with it only via library methods.
61pub type Manager = battery_lib::Manager;
62
63/// Opaque struct representing batteries iterator.
64///
65/// End users should consider it as a some memory somewhere in the heap,
66/// and work with it only via library methods.
67pub type Batteries = battery_lib::Batteries;
68
69/// Opaque struct representing battery.
70///
71/// End users should consider it as a some memory somewhere in the heap,
72/// and work with it only via library methods.
73pub type Battery = battery_lib::Battery;
74
75pub use self::battery::*;
76pub use self::errors::{battery_have_last_error, battery_last_error_length, battery_last_error_message};
77pub use self::iterator::*;
78pub use self::manager::*;
79pub use self::state::*;
80pub use self::technology::*;