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

#316 in Configuration

Download history 282/week @ 2024-03-14 559/week @ 2024-03-21 298/week @ 2024-03-28 311/week @ 2024-04-04 537/week @ 2024-04-11 171/week @ 2024-04-18 219/week @ 2024-04-25 223/week @ 2024-05-02 256/week @ 2024-05-09 1148/week @ 2024-05-16 932/week @ 2024-05-23 762/week @ 2024-05-30 1076/week @ 2024-06-06 1261/week @ 2024-06-13 951/week @ 2024-06-20 749/week @ 2024-06-27

4,176 downloads per month
Used in 13 crates (11 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–3MB
~59K SLoC