Skip to main content

dynamic_config

Attribute Macro dynamic_config 

Source
#[dynamic_config]
Expand description

Turns a struct into a hot-reloadable configuration snapshot.

See the crate documentation for the full guide.

§Arguments

ArgumentFormRequiresDefault
filesfiles = ["a.toml"]one of files / name+paths
namename = "config"paths
pathspaths = ["/etc/app", "."]name
keykey = "db"always
envenv = "APP_"no environment layer
nestnest = "__"env"__"
allow_empty_envflagenvoff — FOO= is unset
profile_envprofile_env = "APP_ENV"no profile overlay
watchflagwatch featureoff
debouncedebounce = 250watch250 ms
poll / poll_intervalflag / = 2000watchnative backend
diffflagoff
validateflaga validate() on the typeoff
saveflagSelf: Serializeoff
cachecache = "last.json"no cache — a bad start fails
cache_modecache_mode = "redacted"cache"full"
env_filesenv_files = [".env"]dotenv feature + envnone
schemaflagschema feature + Self: JsonSchemaoff
asyncflagasync featureoff

One field attribute: #[config(secret)] generates a Debug that prints *** for the marked fields, and forbids #[derive(Debug)] alongside it.

The book’s attribute reference carries a section per argument, with an example and the reasoning behind each default.

§Requirements

The annotated struct must implement serde::Deserialize and be Send + Sync + 'static. Type and const parameters are supported — those go through a TypeId registry rather than a static, at a measured cost of roughly 10 ns per read. A lifetime parameter is rejected at compile time: the snapshot outlives every borrow that could name one. Turns a struct into a hot-reloadable configuration snapshot.

Documented on the re-export in dynamic_config, which is where callers should read it.