get system type in rust

To get the type of the system in Rust, we can use the std::env::consts::OS constant, which returns a string representing the operating system family the program is running on. Here is an example code snippet:

main.rs
fn main() {
    let os_type = std::env::consts::OS;
    println!("System type: {}", os_type);
}
96 chars
5 lines

The std::env::consts module provides other useful constants such as ARCH, DLL_EXTENSION, EXE_EXTENSION, FAMILY, OS_FAMILY, PATH_SEPARATOR, POINTER_WIDTH, and STATIC_LIBRARY_EXTENSION that we can use to get more specifics about the system.

related categories

gistlibby LogSnag