config!() { /* proc-macro */ }Expand description
Declares static variables containing config data.
A config block may contain any number of config items, in the form illustrated below:
ⓘ
config! {
/// Optional documents
#[optional_attributes]
<VIS> static <IDENT> = <SRC>;
/// Optional documents
#[optional_attributes]
<VIS> static <IDENT> = <SRC> + <SRC> + <SRC>;
}Each declaration is simply a typical static item, except that the type is omitted.
The expression part looks like a sum of sources.
This is where overwriting takes place. All variants are completely overwritten except for tables, which got merged recursively.
Every <SRC> takes one of the following forms:
#[toml] r#"name = "Tom""#- an inline literal config. We require an attribute to specify the format of config.include_config!("example_config.toml")- a file inclusion. The path is resolved relative to the current file (similar toinclude_str!()). The format specifier attribute may be omitted if it’s clear from the file extension.include_config_env!("$CARGO_MANIFEST_DIR/examples/example_config.toml")- also a file inclusion, but environment variables of form$ENV_VARare 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.