dotenv-parser

Crates.iodotenv-parser
lib.rsdotenv-parser
version0.1.3
sourcesrc
created_at2020-09-13 10:19:16.082053
updated_at2021-03-05 08:33:59.184519
descriptionPest-based parser for .env files
homepagehttps://github.com/rubik/dotenv-parser
repositoryhttps://github.com/rubik/dotenv-parser
max_upload_size
id288137
size17,326
Michele Lacchia (rubik)

documentation

README

dotenv-parser

Pest-based parser for .env files.

Build Code Coverage Downloads (all time) ISC License

dotenv-parser is a minimal crate that exposes an .env file parser generated by Pest.

Usage

The API is minimal: this crate exposes a single parse_dotenv function which accepts a string reference and returns a BTreeMap wrapped in a Result. The parser handles comments, strings and the export syntax automatically. This program

use dotenv_parser::parse_dotenv;

fn main() {
    let source = r#"
        ENV_FOR_HYDRO='testing 2' # another one here
        export USER_ID=5gpPN5rcv5G41U_S
        API_TOKEN=30af563ccc668bc8ced9e24e  # relax! these values are fake
        APP_SITE_URL=https://my.example.com
    "#;
    println!("{:#?}", parse_dotenv(source).unwrap());
}

prints

{
    "API_TOKEN": "30af563ccc668bc8ced9e24e",
    "APP_SITE_URL": "https://my.example.com",
    "ENV_FOR_HYDRO": "testing 2",
    "USER_ID": "5gpPN5rcv5G41U_S",
}
Commit count: 13

cargo fmt