Operating system information with os_info



examples/other/os-information/Cargo.toml
[package]
name = "os-information"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
os_info = "3.7.0"

examples/other/os-information/src/main.rs
fn main() {
    let info = os_info::get();

    // Print full information:
    println!("OS information: {info}");

    // Print information separately:
    println!("Type: {}", info.os_type());
    println!("Version: {}", info.version());
    println!("Bitness: {}", info.bitness());
    println!("Architecture: {}", info.architecture().unwrap());
}

OS information: Ubuntu 23.10 (mantic) [64-bit]
Type: Ubuntu
Version: 23.10
Bitness: 64-bit
Architecture: x86_64