3 releases

0.1.3 Mar 5, 2021
0.1.2 Sep 13, 2020
0.1.1 Sep 13, 2020
0.1.0 Sep 13, 2020

#460 in Configuration

Download history 674/week @ 2024-07-21 992/week @ 2024-07-28 1554/week @ 2024-08-04 1621/week @ 2024-08-11 926/week @ 2024-08-18 1657/week @ 2024-08-25 2520/week @ 2024-09-01 1197/week @ 2024-09-08 1115/week @ 2024-09-15 1090/week @ 2024-09-22 1752/week @ 2024-09-29 1002/week @ 2024-10-06 1270/week @ 2024-10-13 1006/week @ 2024-10-20 899/week @ 2024-10-27 1289/week @ 2024-11-03

4,496 downloads per month
Used in 14 crates (12 directly)

ISC license

11KB
201 lines

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",
}

Dependencies

~2–2.8MB
~56K SLoC