rsys

Crates.iorsys
lib.rsrsys
version0.5.5
sourcesrc
created_at2020-08-31 17:20:14.216342
updated_at2020-10-03 06:11:17.50025
descriptionCrate for system and hardware information parsing
homepagehttps://github.com/wojciechkepka/rsys
repositoryhttps://github.com/wojciechkepka/rsys
max_upload_size
id283157
size101,367
Wojciech Kępka (vv9k)

documentation

README

rsys

Build Status crates.io crates.io Docs
Crate for aquiring information about host machine and operating system in a os-agnostic fashion.

The common api is available through Rsys struct which compiles conditionally with required methods. The error and result type is available at the root of this crate for convienience while all the methods exposed by Rsys struct are also available in each os module.

Main goals are clear and easy api with as much of the api being os-agnostic.

Example usage:

  • Cargo.toml
[dependencies]
rsys = "0.5"
  • main.rs
use rsys::{Rsys, Result};
fn main() -> Result<()> {
    // You can either use api through Rsys object
    // for os-agnostic experience
    let rsys = Rsys::new();
    println!("HOSTNAME - {}", rsys.hostname()?);
    let iface = rsys.default_iface()?;
    println!("CPU - {}", rsys.cpu()?);
    println!("ARCH - {}", rsys.arch()?);
    println!("MEMORY TOTAL - {}b", rsys.memory_total()?);
    println!("UPTIME - {}s", rsys.uptime()?);
    println!("SWAP TOTAL - {}b", rsys.swap_total()?);
    println!("CPU CORES - {}", rsys.cpu_cores()?);
    println!("CPU CLOCK - {}MHz", rsys.cpu_clock()?);
    println!("IPv4 - {}", rsys.ipv4(&iface)?);
    println!("MAC - {}", rsys.mac(&iface)?);
    println!("INTERFACES - {:#?}", rsys.interfaces()?);

    
    // Or use functions in each module
    if cfg!(target_os = "linux") {
        println!("KERNEL VERSION - {}", rsys::linux::kernel_version()?);
        println!("HOSTNAME - {}", rsys::linux::hostname()?);

        // Os-specific functions are also available as methods
        println!("MEMORY - {:#?}", rsys.memory()?);
        println!("KERNEL_VERSION - {:#?}", rsys.kernel_version()?);
    }
    Ok(())
}

TODO

  • Finish macos common api
  • Finish windows common api
  • Add async feature for async file reads and commands etc...

License

MIT

Commit count: 261

cargo fmt