Skip to main content

Config

Derive Macro Config 

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

Attaches config data to a unit struct.

§Attribute format

#[config(format = "toml")]

All sources within a config type can only share the same format. The format may be omitted if it is clear from extensions of included paths.

Each format has a corresponding feature gate.

§Attribute src

Config sources come in three flavors:

#[config(src = "<SRC_LITERAL>")]
#[config(src = include!("<PATH_LITERAL>"))]
#[config(src = include_env!("<PATH_LITERAL>"))]

There can be an arbitrary number of sources, combined in arbitrary order, as long as they agree on the same format. When there are multiple sources, they got merged recursively per field, with latter ones overwriting former ones.

When including files, the paths are resolved relative to the call site file. include_env! specially supports environment variable interpolation - environment variables of form $ENV_VAR are interpolated. Escape $ with $$. The support of environment variable interpolation is to aid any code analyzer to locate files, as environment variables like $CARGO_MANIFEST_DIR and $OUT_DIR resolve to absolute paths. This is mostly inspired by include_dir crate.