docs / Getting Started / system.os

system.os

system.os covers the process environment, the command line, and the host platform. Env and Args follow the same capability rule as Fs.

use system.io
use system.os

fn main()
    // platform() names the host: "macos", "linux" or "windows".
    println(f"platform: {platform()}")

    // Env is the capability for the process environment.
    let env = Env()
    match env.set("MIRI_GREETING", "hello")
        Result.Ok(replaced): println(f"set (replaced an existing value: {replaced})")
        Result.Err(e): println(f"could not set: {e}")

    // get returns String? — an unset variable is None, not an empty string.
    match env.get("MIRI_GREETING")
        Some(value): println(f"MIRI_GREETING={value}")
        None: println("MIRI_GREETING is unset")

    // Args is Iterable<String> over the command line.
    let args = Args()
    println(f"{args.length()} argument(s)")
    for arg in args
        println(f"  {arg}")
MemberReturnsBehaviour
Env().get(name String)String?An unset variable is None, distinct from a variable set to the empty string.
Env().set(name String, value String)Result<bool, EnvError>true when an existing value was replaced.
Args().length()intNumber of command-line arguments.
Args().element_at(index int)StringOne argument; Args is Iterable<String>, so for..in works.
platform()StringFree function naming the host: macos, linux or windows.
exit(code int)Ends the process with a status code.