Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Attribute reference

Every argument #[dynamic_config(..)] accepts, and every field attribute.

At a glance

ArgumentFormRequiresDefault
filesfiles = ["a.toml", "b.json"]one of files / name+paths
files = []no files at all, on purpose
namename = "config"paths
pathspaths = ["/etc/app", "."]name
keykey = "db"always required
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
pollflagwatchnative backend
poll_intervalpoll_interval = 2000watch2000 ms with poll
diffflagoff
validateflaga validate() on the typeoff
saveflagSelf: Serializeoff
cachecache = "/var/lib/app/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
Field attributeFormEffect
secret#[config(secret)]Debug prints ***; forbids #[derive(Debug)]

Anything else is a compile error listing the arguments that exist.

What the attribute generates

MethodAlwaysDescription
load() -> Result<Self, Error>Read the sources and deserialize. Leaves the snapshot alone.
init() -> Result<(), Error>load() plus install as the initial snapshot.
replace(Self)Atomically swap in a new snapshot.
current() -> Arc<Self>The current snapshot. Panics before init().
try_current() -> Option<Arc<Self>>The current snapshot, or None.
snapshot() -> Result<Snapshot, Error>Resolve without deserializing, for keys with no field.
source_of(path) / is_set(path)Which layer supplies a key, and whether anything does.
check() -> Result<Report, Error>What it resolves to, without loading.
on_reload(f)Run a callback on every later reload.
on_reload_scoped(f) -> HookGuardThe same, until the guard is dropped.
prepare() -> Result<Commit, Error>Load without installing, for a ReloadGroup.
set_default / set_override / set_flagThe three runtime layers.
set_defaults(value)Every field of a Serialize value as defaults, at once.
set_assignments(["k=v"])Apply --set key=value strings.
bind_env(path, "PORT") / clear_env_bindings()Bind a field to an environment variable by name.
clear_defaults / clear_overrides / clear_flagsDrop them again.
start_watch() -> io::Result<WatchHandle>watchReload on file changes. A second call while one runs is AlreadyExists.
save(&self, path)saveWrite back, atomically.
save_new(&self, path)saveThe same, refusing if the file exists.
save_encrypted(&self, path, &encryptor)save + decryptThe same, encrypted.
alias(from, to) / clear_aliases()Keep an old key path working after a rename.
load_async() / init_async()asyncThe same, off the async executor.
changes()asyncA handle woken by every later reload.
set_remote(source) / refresh_remote() / clear_remote()Install a remote store, fetch from it, drop what it gave.
apply_remote(document)Install a document a watch pushed, and reload.
set_remote_async(source) / refresh_remote_async()asyncThe same, for a store whose client is async.
bind_clap(&matches, &[..])clap featureCopy arguments into the flags layer.
schema()schema argumentA JSON Schema for the file this section lives in.