Crate tenvy

Crate tenvy 

Source
Expand description

Parse environment variables into type-safe structures.

use tenvy::Tenvy;

#[derive(Debug, Tenvy)]
struct Environment {
    database_url: String,
    server: Server,
}

#[derive(Debug, Tenvy)]
struct Server {
    addr: std::net::SocketAddr,
    workers: Option<std::num::NonZeroUsize>,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let env: Environment = tenvy::from_env()?;
    println!("{env:#?}");
    Ok(())
}

Structs§

Env
Current context of environment variable parsing.
From
Adapter that parses U and then transforms it into T using From.
FromStr
Adapter that parses T using its FromStr implementation.
TryFrom
Adapter that parses U and then transforms it into T using TryFrom.

Enums§

Error
An error during parsing of environment variables.

Traits§

Tenvy
Parse a value from environment variables.

Functions§

from_env
Parse environment variables into T.

Derive Macros§

Tenvyderive
Derive an implementation of Tenvy for your structure.