rust-env is a VSCode extension that brings auto-completion and type-safe access to .env
keys directly in your Rust codebase.
While developing the backend for QPylon Video Downloader using Rust + Axum, I frequently encountered annoying bugs due to mistyped environment variable keys. Coming from a TypeScript world where I used hansf14-env-typings, I knew the solution: strong editor support.
So I built rust-env — a lightweight, automatic way to sync .env
variables to a Rust module with IntelliSense-friendly constants.
std::env::var("MY_ENV_KEY")
..env
file changes on save.env.rust.json
..env
file and define your keys:API_SERVER_BASE_URL="https://api.example.com"
API_SERVER_HOST="api.example.com"
env.rust.json
:{
"outPath": "./src/rust_env/mod.rs"
}
.env
file, the extension automatically generates the module with the env key constants:#[allow(dead_code)]
pub mod key {
pub const API_SERVER_BASE_URL: &str = "API_SERVER_BASE_URL";
pub const API_SERVER_HOST: &str = "API_SERVER_HOST";
}
use rust_env::key;
let url = std::env::var(key::API_SERVER_BASE_URL).unwrap();