Languages
Envlet for Rust
One small crate. inject fills the process environment, load and get return values, all with typed errors.
Inject
use envlet::{inject, Error, Options};
fn main() -> Result<(), Error> {
inject(&Options::default())?;
let stripe_key = std::env::var("STRIPE_KEY").unwrap();
Ok(())
}Load
use envlet::{load, Error, Options};
fn main() -> Result<(), Error> {
let values = load(&Options::default())?;
let database_url = &values["DATABASE_URL"];
Ok(())
}Get
use envlet::{get, Error, Options};
fn main() -> Result<(), Error> {
let stripe_key = get("STRIPE_KEY", &Options::default())?;
Ok(())
}Install
cargo add envletSet up
- 01
Install
cargo add envlet.
- 02
Set one secret
ENVLET_TOKEN in the environment of the binary.
- 03
Inject in main
Call inject(&Options::default())? before reading std::env.
Questions
- Will my app start if Envlet is down?
- No, and that is the point. The SDK retries for a few seconds, then fails so you notice. It never starts your app with half an environment.
- What does the host need?
- One variable, ENVLET_TOKEN. Everything else arrives at boot.
- Can I still set some values on the Rust host?
- Yes. A value the host already set wins. Pass override if you want Envlet to win instead.