rokdocs
v0.1

rok::std::env

rok::std::env (stdlib spec 306): arguments, environment variables, directories, exit.

set_var has no global lock: call it before spawning threads (306.3). Names and values from the OS are bytes (Windows: its UTF-16 as WTF-8); var / vars / args hand out the UTF-8 ones as str, the *_os forms raw.

Structs

RawStr

pub struct RawStr

Bytes from the OS that need not be UTF-8 (args_os, var_os).

  • pub const fn len(self) -> usize

    Byte length.

  • pub const fn is_empty(self) -> bool
  • pub const fn to_str(self) throws (Utf8Error) -> str

    The bytes as text; throws if they are not UTF-8.

  • pub const fn as_bytes(self) -> List<u8>

    A copy of the bytes.

  • pub fn from_wide(wide: List<u16>) -> RawStr

    UTF-16 units from the OS, lone surrogates allowed.

  • pub fn as_wide(self) -> List<u16>

    The UTF-16 units (a copy, like as_bytes).

Trait implementations 2
  • impl PartialEq for RawStr
  • impl Debug for RawStr

Vars

pub struct Vars
Trait implementations 1
  • impl Iterator for Vars

VarsOs

pub struct VarsOs
Trait implementations 1
  • impl Iterator for VarsOs

JoinPathsError

pub struct JoinPathsError

A join_paths entry that holds the separator.

  • pub path: str
Trait implementations 3
  • impl Display for JoinPathsError
  • impl Debug for JoinPathsError
  • impl Error for JoinPathsError

Enums

VarError

pub enum VarError

Why var gave no str.

  • NotPresent

    The variable does not exist.

  • NotUnicode

    Its value is not UTF-8 (read it with var_os).

Trait implementations 3
  • impl Display for VarError
  • impl Debug for VarError
  • impl Error for VarError

Functions

exit

pub const fn exit(code: i32) -> !

Exit the process now with code (refs-lang 4.16.4); finally and Drop do not run.

args

pub fn args() -> List<str>

Command-line arguments; [0] is the program name.

args_os

pub fn args_os() -> List<RawStr>

The arguments as raw OS bytes.

var

pub fn var(name: str) throws (VarError) -> str

name's value; NotPresent when unset, NotUnicode when not UTF-8.

var_os

pub fn var_os(name: str) -> RawStr | none

name's value as raw bytes, or none.

set_var

pub fn set_var(name: str, value: str)

remove_var

pub fn remove_var(name: str)

vars

pub const fn vars() -> Vars

Every (name, value) pair, a snapshot taken lazily as it goes.

vars_os

pub const fn vars_os() -> VarsOs

vars as raw OS bytes (names and values need not be UTF-8).

current_dir

pub fn current_dir() throws (IoError) -> Path

set_current_dir

pub fn set_current_dir<P: AsPath>(path: P) throws (IoError)

home_dir

pub fn home_dir() -> Path | none

$HOME (Windows: %USERPROFILE%).

temp_dir

pub fn temp_dir() -> Path

$TMPDIR, else /tmp. Windows: the first set of %TMP%, %TEMP%, %USERPROFILE%, %SystemRoot% (as GetTempPath2W).

config_dir

pub fn config_dir() -> Path | none

Per-user configuration: ~/Library/Application Support, %APPDATA%, or $XDG_CONFIG_HOME / ~/.config.

cache_dir

pub fn cache_dir() -> Path | none

Per-user cache: ~/Library/Caches, %LOCALAPPDATA%, or $XDG_CACHE_HOME / ~/.cache.

data_dir

pub fn data_dir() -> Path | none

Per-user data: ~/Library/Application Support, %APPDATA%, or $XDG_DATA_HOME / ~/.local/share.

split_paths

pub const fn split_paths(paths: str) -> List<Path>

paths split on : (Windows: ;, " quoting dropped); empty pieces dropped.

join_paths

pub const fn join_paths<I: Iterator<Item = Path>>(paths: I) throws (JoinPathsError) -> str

paths joined with : (Windows: ;), the PATH form; throws if one holds the separator (or, on Windows, a ").

current_exe

pub fn current_exe() throws (IoError) -> Path

The running executable's absolute path.

pid

pub fn pid() -> u32

parent_pid

pub fn parent_pid() -> u32 | none