Expand description
Dotenv / env-file parser (env feature).
Format: env
§Behaviour
- Splits the UTF-8 input into lines; blank lines and
#comments are ignored, and an optional leadingexportis stripped. - Each remaining
KEY=VALUEline becomes a string entry. Values may be double-quoted (with\n,\r,\t,\",\\escapes), single-quoted (taken literally), or unquoted (used verbatim). The result is always aValue::MapofValue::Strings. - When the source carries a
separatoroption, keys are split on that separator and nested into sub-maps (e.g.BAR__BAZ=valwithseparator=__becomes{bar: {baz: "val"}}). - Each key carries its line/column
Location; for single-line input the line/column are omitted. The root map has no line. - Non-UTF-8 input fails with
Error::InvalidUtf8; there are no syntax errors otherwise.is_format_supportedreturnsSome(true)when any non-comment line contains=, elseSome(false).
§Example
use tanzim_parse::{Parse, env::Env};
use tanzim_source::SourceBuilder;
let source = SourceBuilder::new()
.with_source("file")
.with_resource(".env")
.build()
.unwrap();
let value = Env::new()
.parse(&source, b"SERVER_HOST=\"127.0.0.1\"\n")
.unwrap();
assert_eq!(
value.value().as_map().unwrap().get("server_host").unwrap().value().as_string().unwrap(),
"127.0.0.1"
);Structs§
- Env
- Parser for the
envformat: dotenv / env-fileKEY=VALUElines into a string map.