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§

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§

Kind
The operating system family, fixed when the program was compiled.
Source
Where a fact came from.

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 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_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.