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.rs91 chars5 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