1 unstable release

0.15.1 Feb 28, 2022

#1398 in Procedural macros

Download history 25/week @ 2022-08-12 22/week @ 2022-08-19 10/week @ 2022-08-26 9/week @ 2022-09-02 20/week @ 2022-09-09 37/week @ 2022-09-16 32/week @ 2022-09-23 37/week @ 2022-09-30 13/week @ 2022-10-07 37/week @ 2022-10-14 14/week @ 2022-10-21 23/week @ 2022-10-28 52/week @ 2022-11-04 35/week @ 2022-11-11 18/week @ 2022-11-18 111/week @ 2022-11-25

219 downloads per month
Used in 2 crates

MIT license

44KB
1K SLoC

dotenvy

crates.io CI Released API docs codecov

A well-maintained fork of the dotenv crate.

This library loads environment variables from a .env file. This is convenient for dev environments.

Components

  1. dotenvy crate - A well-maintained fork of the dotenv crate.
  2. dotenvy_codegen crate - A macro for compile time dotenv inspection.
  3. dotenvy_codgen_impl crate - Internal implementation for dotenvy_codegen.
  4. dotenvy CLI tool for running a command using the environment from a .env file (currently Unix only)

Usage

Loading at runtime

use dotenvy::dotenv;
use std::env;

fn main() {
    dotenv().ok();

    for (key, value) in env::vars() {
        println!("{key}: {value}");
    }
}

Loading at compile time

The dotenv! macro provided by dotenvy_codegen crate can be used.

Warning: there is an outstanding issue with rust-analyzer (rust-analyzer #9606) related to the dotenv! macro

Why does this fork exist?

The original dotenv crate has not been updated since June 26, 2020. Attempts to reach the authors and present maintainer were not successful (dotenv-rs/dotenv #74).

This fork is intended to serve as the development home for the dotenv implementation in Rust.

What are the differences from the original?

This repo fixes:

  • home directory works correctly (no longer using the deprecated std::env::home_dir)
  • more helpful errors for dotenv! (dotenv-rs/dotenv #57)

For a full list of changes, read the changelog.

Are you a usurper of the dotenv legacy?

Legend has it that the Lost Maintainer will return, merging changes from dotenvy into dotenv with such thrust that all Cargo.tomls will lose one keystroke. Only then shall the Rust dotenv crateverse be united in true harmony.

Until then, this repo dutifully carries on the dotenv torch. It is actively maintained. Contributions and PRs are very welcome!

Dependencies

~210–620KB
~15K SLoC