Expand description
The operating system: kind, name, version, kernel, and distribution.
The kind and the is_* checks are compile-time constants. Everything else
is a static fact, read once on first use and cached for the life of the
process (about a nanosecond afterwards).
use sys_lib as sys;
println!("{} (kernel {})", sys::os::name(), sys::os::kernel());
println!("{} ({})", sys::os::distro(), sys::os::distro_id()); // "Ubuntu (ubuntu)", "Windows (windows)"
if sys::os::is_like("debian") {
// apt-based: Debian, Ubuntu, Mint, Pop!_OS, ...
}
const ON_WINDOWS: bool = sys::os::is_windows();Structs§
- OsInfo
- Everything this module knows, in one value.
- OsRelease
- The fields of os-release (Linux), or their legacy-file equivalents.
- Version
- A version number, with the original text kept:
24.04stays24.04.
Enums§
Functions§
- distro
- The distribution’s name on Linux (“Ubuntu”, “Fedora Linux”, “Arch Linux”), and the operating system’s elsewhere (“Windows”, “macOS”, “Android”, “iOS”). Never empty; “Linux” when a Linux system says nothing about itself.
- distro_
id - The distribution’s lowercase id on Linux (
ubuntu,fedora,arch), and the operating system’s elsewhere (windows,macos,android,ios). - info
- Everything above in one value.
- is_
android - Android.
- is_bsd
- FreeBSD, OpenBSD, NetBSD, or DragonFly BSD.
- is_ios
- iOS and iPadOS.
- is_like
- Whether the distribution is
idor derives from it (itsIDorID_LIKE):is_like("debian")is true on Debian, Ubuntu, Mint, and Pop!_OS. Off Linux it compares withdistro_id(is_like("windows")on Windows). - is_
linux - The Linux kernel, not Android.
- is_mac
- macOS; the same as
is_macos. - is_
macos - macOS.
- is_unix
- A Unix: Linux, Android, macOS, iOS, the BSDs, …
- is_
windows - Windows.
- kernel
- The kernel release: “6.8.0-45-generic”, “24.1.0” (Darwin), “10.0.26200.6899”.
- kind
- The operating system family this program was compiled for.
- name
- The operating system’s name and version: “Ubuntu 24.04.1 LTS”, “macOS 15.1 Sequoia”, “Windows 11 Pro”. Never empty, never fails: a minimal container without os-release gives “Linux” (E-47).
- os_
release - Every os-release field (Linux).
Noneelsewhere, and on a Linux system with neither os-release nor a legacy release file. - version
- The version:
24.04on Ubuntu,15.1on macOS,10.0.26200.6899on Windows.Noneon rolling distributions, which have none.