feat: add libmacchina

This commit is contained in:
2021-04-18 22:29:11 +08:00
parent d09b72468e
commit 1c58c1cfd2
3 changed files with 546 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
use libmacchina::traits::{
BatteryReadout, BatteryState,
GeneralReadout, KernelReadout,
MemoryReadout,
};
fn main() {
let battery_readout = libmacchina::BatteryReadout::new();
let percentage = battery_readout.percentage();
let state = battery_readout.status();
println!("{}", percentage.unwrap());
println!("{:?}", match state {
Err(e) => format!("Error: {:?}", e),
Ok(BatteryState::Charging) => "Charging".into(),
Ok(BatteryState::Discharging) => "Discharging".into(),
});
let general_readout = libmacchina::GeneralReadout::new();
println!("User name: {}", general_readout.username().unwrap());
println!("IP: {}", general_readout.local_ip().unwrap());
println!("Hostname: {}", general_readout.hostname().unwrap());
let kernel_readout = libmacchina::KernelReadout::new();
println!("OS release: {}", kernel_readout.os_release().unwrap());
println!("OS type: {}", kernel_readout.os_type().unwrap());
println!("Pretty kernel: {}", kernel_readout.pretty_kernel().unwrap());
// let product_readout = libmacchina::ProductReadout::new();
// println!("{}",product_readout.product().unwrap());
// println!("{}",product_readout.name().unwrap());
// println!("{}",product_readout.version().unwrap());
let memory_readout = libmacchina::MemoryReadout::new();
println!("Memory total: {}", memory_readout.total().unwrap());
println!("Memory used: {}", memory_readout.used().unwrap());
println!("Memory free: {}", memory_readout.free().unwrap());
}