env
The env module reports basic process and host information: whether an
environment variable is set, the current working directory, and the operating
system name and CPU architecture.
Import
Section titled “Import”use std::core::envFunctions
Section titled “Functions”env::has(name: string) -> bool
Section titled “env::has(name: string) -> bool”Check whether an environment variable is set.
if env::has("API_KEY") { print("API key configured")}env::cwd() -> string
Section titled “env::cwd() -> string”Get the absolute path of the current working directory.
let dir = env::cwd()print(dir)env::os() -> string
Section titled “env::os() -> string”Get the operating-system name — typically "linux", "macos", or "windows".
let name = env::os()print(name)env::arch() -> string
Section titled “env::arch() -> string”Get the CPU architecture — typically "x86_64" or "aarch64".
let arch = env::arch()print(arch)Function Reference
Section titled “Function Reference”| Function | Signature | Description |
|---|---|---|
env::has(name) | (string) -> bool | Variable is set |
env::cwd() | () -> string | Current working directory |
env::os() | () -> string | Operating-system name |
env::arch() | () -> string | CPU architecture |
Permissions
Section titled “Permissions”Every env function requires the Env permission. In a sandboxed scope
without Env, a call to env::has, env::cwd, env::os, or env::arch
fails with a permission error rather than returning a value.
See Also
Section titled “See Also”- Security & Permissions — the
Envpermission