4 releases (breaking)
0.4.0 | Oct 26, 2024 |
---|---|
0.3.0 | Oct 13, 2024 |
0.2.0 | Oct 7, 2024 |
0.1.0 | Sep 27, 2024 |
#435 in Configuration
208 downloads per month
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