I want to determine the OS of the computer to return a value based on that.
You can get this from the environment variables Cargo sets during compilation.
Depends on how much details you want. Do you only care about windows, mac, linux, freebsd etc? Do you care about versions? What about different Linux distros?
If you do care about all those details there are several crates available: I have used os_info — Rust OS-specific library // Lib.rs myself. Unfortunately on Linux it invokes lsb_release
as a program, rather than parsing /etc/os-release
directly. This adds significant overhead (35 ms or so on my laptop, less on my desktop) which can be a problem if your program is already short-lived.
Thus on Linux, a better option might be to just read and parse /etc/os-release
yourself. It is a very simple newline separated key=value
format.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.