iet-config-macros
Derives typed, source-independent configuration settings.
iet-config-macrostoolingConfiguration deriveHow 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.
// examples/handbook-notes/src/config.rs
// examples/handbook-notes/src/main.rs
let source = snapshot?;
let config: NotesConfig = new.load?;
- A field named
http_addressis read fromNOTES_HTTP_ADDRESS,capacityfromNOTES_CAPACITY. Secret<T>fields load viaiet_config::secret, expose with.expose(), and are redacted fromDebug; secret defaults are rejected at compile time.#[config(prefix = "APP", validate = validate_settings)]infersAPP_*keys and runs a customfn(&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.rssrc/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-notesexamples/skills-only-app
Source: crates/macros/iet-config-macros