envcast_derive 1.0.0

Short, clear description of what the project does
Documentation

envcast_derive

Crates.io msrv 1.70.0 ci docs

Overview

envcast_derive provides the FromEnv procedural macro for Rust structs. It generates a get() method that resolves struct fields using the following order:

  1. Environment variables (field name as-is, then uppercase)
  2. .env files (default .env, then DOTENV_CONFIG_FILE), lowercase and uppercase keys
  3. #[default = "..."] attribute
  4. Default::default()

Each field type must implement:

  • std::str::FromStr
  • Default

Usage

use envcast::FromEnv;

#[derive(FromEnv)]
pub struct Config {
    #[default = 50]
    pub int_field: i32,

    #[default = 50.0]
    pub float_field: f32,

    #[default = "Rust"]
    pub string_field: String,

    #[default = true]
    pub bool_field: bool,
}

Then:

let cfg = Config::get();

Config::get() returns a struct with all fields resolved according to the priority rules above.

License

MIT