If you prefer process environment variables, let the CLI load them before your app starts:
// src/main.rs
fn main() -> Result<(), Box<dyn std::error::Error>> {
let hello = std::env::var("HELLO")?;
println!("Hello {hello}");
Ok(())
}
$ dotenvx run --strict -- cargo run
Hello Secret
For production, install the CLI on the host and wrap your compiled binary:
$ dotenvx run -f .env.production --strict -- ./hello-rust
Hello Production
This uses the CLI's key resolution. The Rust code only reads the resulting environment; it does not call dotenvx-primitives. See CLI run for its options.