4 releases (breaking)

new 0.4.0 Oct 26, 2024
0.3.0 Oct 13, 2024
0.2.0 Oct 7, 2024
0.1.0 Sep 27, 2024

#282 in Configuration

Download history 153/week @ 2024-09-23 27/week @ 2024-09-30 363/week @ 2024-10-07 76/week @ 2024-10-14

619 downloads per month

MIT license

10KB
140 lines

Dotenv+

A dotenv extension for Rust.

Quick Start

Initialize the environment variables and get different variables with the following code:

use dotenv_plus::{
    env::DotEnv,
    common::get_rust_env,
    var::{set_var, var},
};

DotEnv::new().done();
assert_eq!(get_rust_env(), "development");
set_var("key", "value");
assert_eq!(var("key"), "value");

License

This project is MIT licensed, you can find the license file here.


lib.rs:

Dotenv+

A dotenv extension for Rust.

Define Different Environments

To define different environments, you may use the features attribute in Cargo.toml:

[features]
dev = []
test = []
prd = []

Then initialize the environment variables with the following code:

use dotenv_plus::env::{DotEnv, Environment};

let environment: Environment = if cfg!(feature = "prd") {
    Environment::Production
} else if cfg!(feature = "test") {
    Environment::Test
} else {
    Environment::Development
};

DotEnv::init()
    .environment(environment.as_code())
    .done();

And run the process with the environment planned to be used:

cargo run --features dev

You may setup and read different environment variables with set_var, get_vars, get_var and var:

use dotenv_plus::var::{set_var, var};

set_var("key", "value");
assert_eq!(var("key"), "value");

Dependencies

~48KB