system-info 0.1.2

Library to get system information
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use system_info::HostName;

#[test]
fn should_get_host_name() {
    let expected = std::process::Command::new("hostname").output().expect("Get hostname");
    let expected = expected.stdout.as_slice();
    let expected = core::str::from_utf8(expected).expect("utf-8 hostname").trim();

    println!("expected hostname={}", expected);
    let name = match HostName::get() {
        Some(name) => name,
        None => panic!("Cannot get hostname: {}", std::io::Error::last_os_error()),
    };
    assert_eq!(name.as_bytes(), expected.as_bytes());
    assert_eq!(name.as_str(), Ok(expected));
}