Skip to main content

Configulator

Struct Configulator 

Source
pub struct Configulator<C> { /* private fields */ }
Expand description

Builder for loading configuration from multiple sources into a typed struct.

Sources are applied in precedence order: defaults < file < env vars < CLI flags.

Available sources depend on enabled feature flags (file, env, cli).

Implementations§

Source§

impl<C: ConfigFields + FromValueMap + Default> Configulator<C>

Source

pub fn new() -> Self

Create a new builder.

Source

pub fn with_file(self, opts: FileOptions) -> Self

Available on crate feature file only.

Enable loading from a config file.

The FileOptions must include a FileLoader implementation that parses the file contents. Use serde_loader for any serde-compatible format.

Source

pub fn with_environment_variables( self, opts: EnvironmentVariableOptions, ) -> Self

Available on crate feature env only.

Enable loading from environment variables.

Source

pub fn with_cli_flags(self, opts: CLIFlagOptions) -> Self

Available on crate feature cli only.

Enable loading from CLI flags.

Source

pub fn with_cli_command(self, cmd: Command) -> Self

Available on crate feature cli only.

Provide a custom clap::Command as the base for CLI flag parsing.

Configulator will add its own config arguments to this command, allowing you to define additional flags, set the app name/version, or customise help output.

Custom args must not share IDs with config field names — clap will error at parse time if an arg ID is registered twice.

Source

pub fn load(self) -> Result<C, ConfigulatorError>
where C: Validate,

Load configuration, applying validation.

Source

pub fn load_without_validation(self) -> Result<C, ConfigulatorError>

Load configuration without running validation.

Source

pub fn defaults_only() -> Result<C, ConfigulatorError>

Get the default config (all defaults applied, no other sources).

Validation is not performed. Call Validate::validate on the result if needed.

Trait Implementations§

Source§

impl<C: ConfigFields + FromValueMap + Default> Default for Configulator<C>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for Configulator<C>

§

impl<C> !UnwindSafe for Configulator<C>

§

impl<C> Freeze for Configulator<C>

§

impl<C> Send for Configulator<C>
where C: Send,

§

impl<C> Sync for Configulator<C>
where C: Sync,

§

impl<C> Unpin for Configulator<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for Configulator<C>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.