get system platform in rust

You can get the system platform in Rust by using the std::env::consts::OS constant. This returns a string that represents the operating system (OS) on which the current code is being executed.

Here's an example:

main.rs
fn main() {
    let os = std::env::consts::OS;
    println!("Operating system: {}", os);
}
91 chars
5 lines

This will print the current operating system to the console. The value returned by std::env::consts::OS can be one of the following strings:

  • "linux"
  • "macos"
  • "ios"
  • "freebsd"
  • "dragonfly"
  • "netbsd"
  • "openbsd"
  • "solaris"
  • "windows"

This information can be useful if you need to write OS-specific code or if you want to provide OS-specific behavior in your Rust program.

gistlibby LogSnag