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

#448 in Configuration

Download history 925/week @ 2024-08-17 1527/week @ 2024-08-24 2653/week @ 2024-08-31 1214/week @ 2024-09-07 1097/week @ 2024-09-14 1110/week @ 2024-09-21 1673/week @ 2024-09-28 1075/week @ 2024-10-05 1288/week @ 2024-10-12 996/week @ 2024-10-19 889/week @ 2024-10-26 1262/week @ 2024-11-02 1319/week @ 2024-11-09 968/week @ 2024-11-16 1127/week @ 2024-11-23 2003/week @ 2024-11-30

5,630 downloads per month
Used in 15 crates (13 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