Module env
Process environment: command-line arguments, environment variables, current working directory, and platform-aware user directories.
Mirrors the layout of Rust's std::env. Platform/architecture detection
and child-process spawning live in std/process.
Stability
unstable, and closer to freezing than most of this group: the shapes are
Rust's std::env and are not expected to move. What is open is error
reporting. args, env, cwd and the user-directory functions report
failure in three different ways across this module — some return an
Option, some a Result(_, IoError), some throw — because they were
added at different times, and D1 wants one answer per kind of failure.
Freezing means picking it, which will change a signature or two.
The user-directory functions (home_dir, config_dir, cache_dir,
temp_dir) also encode a per-platform convention (XDG on Linux,
~/Library on macOS, %APPDATA% on Windows). Those conventions are
deliberate and documented per function; a caller that needs a different
one should build the path itself rather than expect a knob here.
Functions
Get the absolute path of the current executable.
The path is symlink-resolved on macOS/Linux (via /proc/self/exe on
Linux, _NSGetExecutablePath + realpath on macOS) and comes from
GetModuleFileNameW on Windows.
Mirrors Rust's std::env::current_exe: Err(IoError) on failure, and
Err(IoError.NotSupported) on platforms with no way to discover the
executable (wasm).
Change the current working directory to path.
Mirrors Rust's std::env::set_current_dir: Ok(()) on success, or
Err(IoError) carrying the real OS reason — e.g. IoError.NotFound when
path does not exist.
Parameters
| Name | Type | Notes |
|---|---|---|
path | Path |
Constants
Environment variable access and manipulation.
Value: source_namespace_yo_id_41984(get: <fn(name)>, set: <fn(name, value, overwrite)>, remove: <fn(name)>, vars: <fn()>)