pub enum ConfigSource {
Defaults,
File(PathBuf),
MergeFile(PathBuf),
Env {
prefix: Option<String>,
},
// some variants omitted
}Expand description
Specifies where configuration values should be loaded from.
Sources are applied in order. By default, later sources overwrite earlier
values (File, Env).
MergeFile is an exception: it only fills in
fields that haven’t been set by a prior source.
§Conventional ordering
&[
ConfigSource::Defaults, // lowest priority
ConfigSource::File(global_config), // e.g. ~/.config/app/config.toml
ConfigSource::MergeFile(local_config), // e.g. .app/config.toml
ConfigSource::Env { prefix: Some("APP".into()) }, // highest priority
]With this ordering, the local config file supplements the global one (missing local fields fall back to global values) while env vars always win.
Variants§
Defaults
Apply compile-time defaults declared with #[param(default = ...)].
Should almost always be the first source so that explicit values from files or environment variables can override them.
File(PathBuf)
Read a TOML file at the given path.
Later sources — including other File entries — overwrite values set
here. Use MergeFile when you want a file
to supplement rather than replace earlier values.
Missing files are silently skipped (not an error) so that optional config files work without extra boilerplate.
MergeFile(PathBuf)
Like File, but only fills in fields that are
still unset after all previous sources.
Use this for layered config (global → project → env): a project-local file should add or override specific keys, not erase values inherited from the global config.
&[
ConfigSource::Defaults,
ConfigSource::File(global), // global config: sets host, port, …
ConfigSource::MergeFile(local), // local config: only overrides what it explicitly sets
ConfigSource::Env { prefix: Some("APP".into()) },
]Missing files are silently skipped, same as File.
Env
Read environment variables.
Each field is looked up under {PREFIX}_{FIELD_UPPER} (e.g. prefix
"APP", field host → APP_HOST). An explicit #[param(env = "X")]
overrides the generated name entirely.
prefix is uppercased automatically; None means no prefix.
Trait Implementations§
Source§impl Clone for ConfigSource
impl Clone for ConfigSource
Source§fn clone(&self) -> ConfigSource
fn clone(&self) -> ConfigSource
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more