crates.io ↗

iet-config-macros

tooling tooling official

Derives typed, source-independent configuration settings.

CoreFeaturesIntegrationsStacksTooling
Used byiet-auth-basiciet-auth-session-jwtiet-auth-session-opaqueiet-db-timescaleiet-http-axum
iet-config-macrostoolingConfiguration derive
Depends onnothing — it stands alone

How to use it

#[derive(Configuration)] turns a named struct into a typed, source-independent configuration reader: each field becomes a logical key parsed and validated through iet_config::Configuration, so a malformed supplied value fails startup instead of silently falling back. Field names map to uppercase keys, #[config(prefix = "...")] scopes them, and default, range, non_empty, secret, seconds, key, and validate options control behaviour.

rust
// examples/handbook-notes/src/config.rs
#[derive(Debug, iet_config_macros::Configuration)]
pub struct NotesConfig {
    /// Address the JSON API listens on (default `127.0.0.1:3012`).
    #[config(default = "127.0.0.1:3012")]
    pub http_address: std::net::SocketAddr,
    /// Maximum number of notes kept in memory (default 1000).
    #[config(default = 1000, range(min = 1, max = 100_000))]
    pub capacity: usize,
}

// examples/handbook-notes/src/main.rs
let source = EnvSource::snapshot("NOTES")?;
let config: NotesConfig = ConfigLoader::new(source).load()?;
  • A field named http_address is read from NOTES_HTTP_ADDRESS, capacity from NOTES_CAPACITY.
  • Secret<T> fields load via iet_config::secret, expose with .expose(), and are redacted from Debug; secret defaults are rejected at compile time.
  • #[config(prefix = "APP", validate = validate_settings)] infers APP_* keys and runs a custom fn(&Self) -> iet_config::Result<()>.

How it works

The derive parses the struct and its #[config(...)] attributes at compile time and emits an impl iet_config::Configuration; load picks a reader per field (required, with_default, secret, optional), and validate runs the generated non_empty/range checks followed by any custom function.

flowchart LR
  S["struct with config attributes"] --> D["derive Configuration"]
  D --> E["configuration expand"]
  E --> L["generated load"]
  E --> V["generated validate"]
  L --> RS["required / with_default / secret / optional"]
  V --> CK["non_empty and range checks"]
  V --> CU["custom validate fn"]

What it implements

  • Concrete mechanism; see the public API below.

What's inside

Modules

  • src/configuration.rs
  • src/lib.rs

Public API

(root)

  • pub fn configuration(input: proc_macro::TokenStream) -> proc_macro::TokenStream

configuration

  • pub fn expand(item: DeriveInput) -> syn::Result<TokenStream>

renamed::src::lib

  • struct Settings

Impl map

  • ConfigSource for Source

Depends on

  • No other framework crate: it stands alone.

External crates: proc-macro-crate, proc-macro2, quote, syn

Used by

In this repository

  • examples/handbook-notes
  • examples/skills-only-app

Source: crates/macros/iet-config-macros