Skip to main content

Loader

Struct Loader 

Source
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

Source

pub fn new() -> Self

A loader with nothing in it yet.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Loader

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Loader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Loader

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.