1mod apple_smart_bettery;
2mod error;
3
4use std::io::Cursor;
5
6use error::Result;
7
8pub struct IOReg();
9
10impl IOReg {
11 pub fn apple_smart_battery() -> Result<apple_smart_bettery::AppleSmartBattery> {
12 let res = std::process::Command::new("ioreg")
13 .arg("-a")
14 .arg("-r")
15 .arg("-c")
16 .arg("AppleSmartBattery")
17 .output()?
18 .stdout;
19 let cursor = Cursor::new(res);
20 let reader = plist::stream::Reader::new(cursor);
21 let mut deserializer = plist::Deserializer::new(reader);
22 let mut res: Vec<_> = serde_path_to_error::deserialize(&mut deserializer).unwrap();
23 Ok(res.pop().unwrap())
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 #[test]
32 fn test_apple_smart_battery() {
33 let battery = IOReg::apple_smart_battery();
34 println!("{:?}", battery);
35 }
36
37 #[test]
38 fn print_value() {
39 let res = std::process::Command::new("ioreg")
40 .arg("-a")
41 .arg("-r")
42 .arg("-c")
43 .arg("AppleSmartBattery")
44 .output()
45 .unwrap()
46 .stdout;
47 let value: plist::Value = plist::from_bytes(&res).unwrap();
48 println!("{:?}", value);
49 }
50}