Expand description
This crate is for expanding environment variables in strings 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}}")?;
// here's where it shines: you can expand an entire string!
let expanded_str = expand("holy mackerel there's a ${MISSING_VAR:-$FOO} and even a $BAR!!")?;Modules§
- errors
- Custom error type(s).
Functions§
- expand
- Parse through a byte slice, expanding envvars along the way.