pub struct Loader { /* private fields */ }Expand description
Builds a Config out of a base file and drop-in directories.
let config = Loader::new()
.base("/etc/zerodds/zerodds.yaml")
.drop_in_dir("/etc/zerodds/zerodds.d")
.drop_in_dir("/run/zerodds/zerodds.d")
.load()?;
// Where did this come from?
println!("{:?}", config.origin_of("transport.mtu"));Implementations§
Source§impl Loader
impl Loader
Sourcepub fn base(self, path: impl AsRef<Path>) -> Self
pub fn base(self, path: impl AsRef<Path>) -> Self
The base file, read before every drop-in.
Absent by default: a package can ship only drop-ins, and a site can run with only a base.
Sourcepub fn require_base(self) -> Self
pub fn require_base(self) -> Self
Fail rather than continue when the base file is not there.
Off by default, because “no configuration” is a legitimate state and a
daemon that starts on its built-in defaults is what an empty
/etc/zerodds should produce. On for a caller who passed --config
and means it.
Sourcepub fn drop_in_dir(self, path: impl AsRef<Path>) -> Self
pub fn drop_in_dir(self, path: impl AsRef<Path>) -> Self
Adds a drop-in directory, after the ones already added.
Directories are read in the order they are added — a package
directory, then a site one, then a runtime one — and inside each
directory the files are read sorted by name. 10-net.yaml before
20-net.yaml before 99-local.yaml, which is the ordering every
systemd drop-in already follows and therefore the one an operator will
assume without being told.
A directory that does not exist is not an error. Half the point of
drop-ins is that /run/... exists only sometimes.
Sourcepub fn extension(self, ext: Option<&str>) -> Self
pub fn extension(self, ext: Option<&str>) -> Self
Only files with this extension are read from drop-in directories.
yaml by default. None reads every file, which is what a directory
of .conf fragments needs. Either way .rpmnew, .dpkg-dist and
editor backups stay out when the default is kept — a package upgrade
leaving zerodds.yaml.rpmnew behind must not quietly change what runs.
Sourcepub fn load(&self) -> Result<Config, ConfigError>
pub fn load(&self) -> Result<Config, ConfigError>
Reads everything and merges it.
§Errors
ConfigError::Io for an unreadable file (and for a missing base
after Self::require_base), ConfigError::Syntax for text outside
the subset, ConfigError::IncludeCycle and
ConfigError::IncludeTooDeep for include chains that do not end.
Sourcepub fn load_onto(&self, config: Config) -> Result<Config, ConfigError>
pub fn load_onto(&self, config: Config) -> Result<Config, ConfigError>
Reads everything and merges it over config, which keeps its sources
and loses every value a file sets again. The environment layer goes in
here, so that the files win over it and a drop-in’s +name appends to
what it set.
§Errors
As Self::load.