Crate expandenv

Source
Expand description

This crate is for expanding environment variables and tilde’s (~) with support for fallback values.

§Examples

// when you expand a variable, it returns the value
let envvar_value = expand("$FOO")?;

// if expansion fails, you can return an error...
assert!(expand("$MISSING_VAR").is_err());
// or try to parse a fallback value
let envvar_value = expand("${MISSING_VAR:-/some/path}")?;
// and nest them as much as you want! this example returns the value of `$FOO`
let envvar_value = expand("${MISSING_VAR:-${ANOTHER_MISSING_VAR:-$FOO}}")?;

// it's not limited; you can expand an entire path!
// the `~` expands to your home directory for simplicity
let path = expand("~/${MISSING_VAR:-$FOO}/file.txt")?;

Modules§

errors

Functions§

expand
Convert a &str slice into a PathBuf, expanding envvars and the leading tilde ~, if it is there.