- First Add the dependency dotenv in your Cargo.toml
[dependencies]
dotenv="*"
- Load the .env file in your code
dotenv::from_path("./.env").expect("error loading env");
- Use the standard library for get your variables
let db_users = env::var("DB_USER").expect("env error");
let db_password = env::var("DB_PASSWORD").expect("env error");