Skip to main content

parse

Function parse 

Source
pub fn parse(path: &Path) -> Result<IndexMap<String, String>>
Expand description

Parse a .env file at path into an ordered key→value map.

§Errors

Returns an error if:

  • the file cannot be read,
  • a non-blank, non-comment line has no = separator, or
  • a key is empty.

§Example

Given the file:

# comment
DATABASE_URL=postgres://localhost/mydb
SECRET_KEY="s3cr3t"
use std::path::Path;
use envx_secure::parser;

let map = parser::parse(Path::new(".env")).unwrap();
assert_eq!(map["DATABASE_URL"], "postgres://localhost/mydb");
assert_eq!(map["SECRET_KEY"], "s3cr3t");