Skip to main content

Module os

Module os 

Source
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.04 stays 24.04.

Enums§

Confidence
How sure an answer is.
FormFactor
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”. None where 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_ID on Linux. None elsewhere.
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 id or derives from it (its ID or ID_LIKE): is_like("debian") is true on Debian, Ubuntu, Mint, and Pop!_OS. Off Linux it compares with distro_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. None where 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). None elsewhere, and on a Linux system with neither os-release nor a legacy release file.
version
The version: 24.04 on Ubuntu, 15.1 on macOS, 10.0.26200.6899 on Windows. None on rolling distributions, which have none.