std/env
Environment variable access.
from "std/env" import { Env }Functions
Env.get
fn Env.get(name: string): Option<string>Look up an environment variable. Returns None if unset.
match Env.get("HOME") {
Some(home) => writeStdout(home),
None => writeStdout("HOME not set"),
}Env.getOr
fn Env.getOr(name: string, fallback: string): stringLook up an environment variable with a default.
let port = Env.getOr("PORT", "8080")Env.set
fn Env.set(name: &string, value: &string): Result<Unit, EnvError>Set a variable in this process's environment, replacing any current value. Children spawned afterwards inherit it; the parent shell never sees it. To give one child a variable without changing your own environment, use Command.env in std/process.
EnvError.InvalidName means the name was empty or contained =.
let _ = Env.set("RUST_LOG", "debug")!Not thread-safe
C's setenv may free the block a concurrent getenv is reading, and no platform offers a thread-safe version. It is safe from a single-threaded program and from green tasks (which never switch inside this call), but not concurrently with Promise.blocking work, which runs on real OS threads and may call getenv through any C library. Set the environment during startup, before spawning anything — the same advice Go and Rust give.
Env.remove
fn Env.remove(name: &string): Result<Unit, EnvError>Remove a variable from this process's environment. Removing a name that is not set succeeds. Same thread-safety limits as Env.set.