envcast_derive

Crates.ioenvcast_derive
lib.rsenvcast_derive
version1.0.0
created_at2025-12-28 06:05:30.575508+00
updated_at2025-12-28 06:05:30.575508+00
descriptionShort, clear description of what the project does
homepagehttps://github.com/neamaddin/envcast
repositoryhttps://github.com/neamaddin/envcast
max_upload_size
id2008287
size10,009
Neamaddin Akhmedov (neamaddin)

documentation

README

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

Commit count: 0

cargo fmt