Function rs_release::get_os_release

source ·
pub fn get_os_release() -> Result<HashMap<Cow<'static, str>, String>>
Expand description

Tries to find and parse os-release in common paths. Stops on success.

Examples found in repository?
examples/who_eats_my_hard_drive.rs (line 12)
11
12
13
14
15
16
fn get_os_id() -> Result<String, Error> {
    match rs_release::get_os_release() {
        Err(_) => Err(Error::ReadError),
        Ok(mut os_release) => os_release.remove("ID").ok_or(Error::UnknownOs),
    }
}
More examples
Hide additional examples
examples/get_os_release.rs (line 12)
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
fn main() {
    let mut args = env::args();

    let os_release = if let Some(os_release_path) = args.nth(1) {
        parse_os_release(os_release_path)
    } else {
        get_os_release()
    };

    match os_release {
        Ok(os_release) => {
            println!("Parsed os-release:");
            for (k, v) in os_release {
                println!("{}={}", k, v);
            }
        }
        Err(e) => eprintln!("ERROR: {e}"),
    }
    println!();

    // You could also parse data from a string
    if let Ok(os_release) = parse_os_release_str("NAME = Fedora") {
        println!("Parsed os-release from &str:");
        for (k, v) in os_release {
            println!("{}={}", k, v);
        }
    }
}