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>
impl<C: ConfigFields + FromValueMap + Default> Configulator<C>
Sourcepub fn with_file(self, opts: FileOptions) -> Self
Available on crate feature file only.
pub fn with_file(self, opts: FileOptions) -> Self
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.
Sourcepub fn with_environment_variables(
self,
opts: EnvironmentVariableOptions,
) -> Self
Available on crate feature env only.
pub fn with_environment_variables( self, opts: EnvironmentVariableOptions, ) -> Self
env only.Enable loading from environment variables.
Sourcepub fn with_cli_flags(self, opts: CLIFlagOptions) -> Self
Available on crate feature cli only.
pub fn with_cli_flags(self, opts: CLIFlagOptions) -> Self
cli only.Enable loading from CLI flags.
Sourcepub fn with_cli_command(self, cmd: Command) -> Self
Available on crate feature cli only.
pub fn with_cli_command(self, cmd: Command) -> Self
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.
Sourcepub fn load(self) -> Result<C, ConfigulatorError>where
C: Validate,
pub fn load(self) -> Result<C, ConfigulatorError>where
C: Validate,
Load configuration, applying validation.
Sourcepub fn load_without_validation(self) -> Result<C, ConfigulatorError>
pub fn load_without_validation(self) -> Result<C, ConfigulatorError>
Load configuration without running validation.
Sourcepub fn defaults_only() -> Result<C, ConfigulatorError>
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.