Skip to main content

Config

Derive Macro Config 

Source
#[derive(Config)]
{
    // Attributes available to this derive:
    #[usage]
}
Expand description

Compile a settings struct into its own registry, reader, and spec config block.

The struct the CLI already holds its settings in becomes the declaration: field types are the settings’ types, doc comments are their help, and #[usage(...)] carries what a spec’s prop node would — env, default, merge, scope, choices, source bindings. The derive generates SETTINGS_PROPS, SETTINGS_REGISTRY, SETTINGS_SPEC, read(&Resolved), and spec_kdl(), so the registry, the reader, and the documentation cannot drift from the struct or from each other. The whole field vocabulary is in the guide: https://usage.jdx.dev/rust/configuration.

#[derive(usage::Config)]
struct Settings {
    /// How many jobs to run at once
    #[usage(env = "EX_JOBS", default = 4, cli("--jobs", "-j"))]
    jobs: u64,
    #[usage(flatten)]
    task: TaskSettings,
}

A group flattens into another with #[usage(flatten)], declaring its dotted keys under its own #[usage(prefix = "task")]. The joined registry refuses duplicate keys at compile time.