This repository contains small scripts as well as instructions to read .env files in several languages.
Cargo.toml
file:[dependencies]
dotenv = "0.15.0"
Having done this, you can take use of the dotenv()
function to load the variables from .dotenv
and then use the env::var
function to access them normally:
extern crate dotenv;
use dotenv::dotenv;
use std::env;
fn main() {
dotenv().ok();
let db_name = env::var("DB_NAME").unwrap();
println!("{}", db_name);
}