crates.io ↗

iet-config-env

feature implementation official

Snapshots the process environment once; no dotenv or background reload.

CoreFeaturesIntegrationsStacksTooling
Used byno framework crate yetexamples/handbook-notesexamples/htmx-starterexamples/skills-only-app
iet-config-envimplementationEnvironment configuration source
Depends oniet-corecontractiet-configcontract

How to use it

iet-config-env reads one immutable snapshot of process environment variables and exposes it as an iet-config source. Give it an uppercase prefix; the prefix is stripped and the rest becomes the logical key that ConfigLoader maps onto a typed configuration struct.

rust
// examples/handbook-notes/src/main.rs (type from src/config.rs)
use iet_config::ConfigLoader;
use iet_config_env::EnvSource;

#[derive(Debug, iet_config_macros::Configuration)]
pub struct NotesConfig {
    #[config(default = "127.0.0.1:3012")]
    pub http_address: std::net::SocketAddr,
    #[config(default = 1000, range(min = 1, max = 100_000))]
    pub capacity: usize,
}

// APP_DATABASE_URL is looked up as DATABASE_URL under prefix APP.
// NOTES_HTTP_ADDRESS here maps to `http_address`.
let source = EnvSource::snapshot("NOTES")?;
let config: NotesConfig = ConfigLoader::new(source).load()?;
  • Prefixes and keys must match [A-Z][A-Z0-9_]* (max 128 chars); unrelated or non-Unicode keys are ignored, while a malformed selected value fails startup instead of falling back.
  • Duplicate selected keys are an error, and Secret values never appear in Debug output or error messages.
  • For deterministic tests, use EnvSource::from_iter("NOTES", entries) instead of mutating the process environment.

How it works

EnvSource::snapshot reads the process environment once; only keys with the uppercase prefix and a valid suffix are kept, and each value is wrapped in a Secret. The resulting EnvSource implements the iet-config ConfigSource trait, and ConfigLoader::load reads the logical keys out of it, applies defaults and ranges, and builds the typed struct.

flowchart LR
  A["EnvSource::snapshot"] --> B["process environment"]
  B --> C["strip prefix"]
  C --> D{"identifier valid"}
  D -->|no| E["config.env_key error"]
  D -->|yes| F["Secret value"]
  F --> G["ConfigSource::get"]
  G --> H["ConfigLoader::load"]
  H --> I["typed configuration struct"]

What it implements

  • Implements iet_config::ConfigSource from iet-config.

What's inside

Modules

  • src/lib.rs

Public API

(root)

  • struct EnvSource
  • pub fn snapshot(prefix: &str) -> AppResult<Self> — APP_DATABASE_URL is looked up as DATABASE_URL under prefix APP.
  • pub fn from_iter( prefix: &str, entries: impl IntoIterator<Item = (OsString, OsString)>, ) -> AppResult<Self> — Deterministic/test source without mutating global process environment.

Impl map

  • ConfigSource for EnvSource

Depends on

Used by

  • No other framework crate depends on it directly.

In this repository

  • examples/handbook-notes
  • examples/htmx-starter
  • examples/skills-only-app
  • examples/skills-only-app-task-tracker

Source: crates/features/iet-config-env