Crates.io | rustdotenv |
lib.rs | rustdotenv |
version | 0.1.2 |
source | src |
created_at | 2021-10-21 19:04:41.932945 |
updated_at | 2021-10-21 19:18:15.399185 |
description | A tool to load env files into the environment |
homepage | |
repository | https://github.com/nilpntr/rustdotenv |
max_upload_size | |
id | 468863 |
size | 4,073 |
A tool to load env files into the environment
Add to your cargo.toml
file
[dependencies]
rustdotenv = "0.1.2"
.env
file
MONGO_URI=mongodb://admin:password@127.0.0.1:27017/?authSource=admin
main.rs
file
use rustdotenv::load;
fn main() {
// If u don't provide the optional Vec<String> then it will load as default the .env file
load(None);
let result = std::env::var("MONGO_URI");
if result.is_err() {
println!("MONGO_URI env var not found");
} else {
println!("MONGO_URI: {}", result.unwrap())
}
}