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§
- Detection
- An answer, where it came from, and how sure it is.
- 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§
- Confidence
- How sure an answer is.
- Form
Factor - What kind of machine this is.
- Kind
- The operating system family, fixed when the program was compiled.
- Source
- Where a fact came from.
Functions§
- codename
- The release’s codename: “Sequoia”, “noble”.
Nonewhere it has none. - detect_
form_ factor - The form factor with where it came from. Cached.
- 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). - edition
- The edition: “Professional”, “ServerDatacenter” on Windows, the os-release
VARIANT_IDon Linux.Noneelsewhere. - form_
factor - What kind of machine this is. Detection is advisory: do not make security decisions on it.
- info
- Everything above in one value.
- is_
64bit - Whether the OS is 64-bit, whatever this process is (WOW64, ARM64 emulation).
- is_
android - Android.
- is_bsd
- FreeBSD, OpenBSD, NetBSD, or DragonFly BSD.
- is_
desktop - A desktop.
- is_ios
- iOS and iPadOS.
- is_
laptop - A laptop or a convertible.
- 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_
mobile - A phone, tablet, handheld, or wearable.
- is_
phone - A phone.
- is_
server - The chassis or the platform role says server.
- is_
server_ edition - Whether this is a server edition: Windows Server.
Nonewhere the question has no meaning. - is_
tablet - A tablet.
- 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.