1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
cfg_if! {
    if #[cfg(target_os = "linux")] {
        mod linux;

        pub type BatteryIterator = linux::SysFs;
        pub type BatteryDevice = linux::SysFsDevice;
    } else if #[cfg(target_os = "macos")] {
        mod darwin;

        pub type BatteryIterator = darwin::IoReg;
        pub type BatteryDevice = darwin::IoRegDevice;
    } else {
        compile_error!("Support for this target OS is not implemented yet!\n \
            You may want to create an issue: https://github.com/svartalf/rust-battery/issues/new");
    }
}

use crate::Battery;

/// Returns an iterator with batteries states.
///
/// # Example
///
/// ```edition2018
/// # use battery::get;
/// #
/// # fn main() {
/// for (idx, bat) in get().enumerate() {
///     println!("Battery {} state: {}", idx, bat.state());
/// }
/// # }
/// ```
pub fn get() -> impl Iterator<Item=Battery> {
    BatteryIterator::new()
}