Crate platform_info

Source
Expand description

Crates.io License CodeCov

This crate provides the ability to retrieve information specific to your current platform via a cross-platform uname-type API (UNameAPI). Additional platform-specific information may be supplied within PlatformInfo.

§Usage

This crate is available on crate.io. So, to use it in your project, just add the following to your project’s Cargo.toml dependencies:

[dependencies]
platform-info = "2"

§Examples

// examples/ex.rs
// * use `cargo run --example ex` to execute this example

// spell-checker:ignore (API) nodename osname sysname

use platform_info::{PlatformInfo, PlatformInfoAPI, UNameAPI};

fn main() {
    let info = PlatformInfo::new().expect("Unable to determine platform info");
    // println!("info={:#?}", info); // note: info *may* contain extra platform-specific fields

    println!("{}", info.sysname().to_string_lossy());
    println!("{}", info.nodename().to_string_lossy());
    println!("{}", info.release().to_string_lossy());
    println!("{}", info.version().to_string_lossy());
    println!("{}", info.machine().to_string_lossy());
    println!("{}", info.osname().to_string_lossy());
}

Other examples can be found in the examples directory of this crate and in the uutils/coreutils implementation of uname.

Structs§

PlatformInfo
Handles initial retrieval and holds cached information for the current platform (a Unix-like OS in this case).
UTSName
Contains information about the current computer system.

Traits§

PlatformInfoAPI
Defines the full API for PlatformInfo.
UNameAPI
Defines a trait API providing uname (aka “Unix name”) style platform information.

Type Aliases§

PlatformInfoError
The common error type for PlatformInfoAPI. Standard thread-safe error type (boxed to allow translation for any std::error::Error type)