pub struct ConfigLoader { /* private fields */ }Expand description
Loads typed configuration from ordered source adapters.
ConfigLoader::app() / ConfigLoader::new() keeps the service-oriented policy:
defaults → TOML → profile dotenv → dotenv → adapter sources → env → overrides.
ConfigLoader::toml(path) is deterministic file-only loading.
ConfigLoader::custom() only loads explicitly provided sources.
Implementations§
Source§impl ConfigLoader
impl ConfigLoader
Sourcepub fn toml(path: impl Into<PathBuf>) -> Self
pub fn toml(path: impl Into<PathBuf>) -> Self
Create a deterministic single-TOML loader.
This policy does not read dotenv files or process environment variables.
Sourcepub fn with_default(
self,
key: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn with_default( self, key: impl Into<String>, value: impl Into<Value>, ) -> Self
Set a programmatic default value.
Defaults are loaded before all configured sources.
Sourcepub fn with_config_file(self, path: impl Into<PathBuf>) -> Self
pub fn with_config_file(self, path: impl Into<PathBuf>) -> Self
Explicitly set the TOML config file path for app loading.
Sourcepub fn with_env_file(self, path: impl Into<PathBuf>) -> Self
pub fn with_env_file(self, path: impl Into<PathBuf>) -> Self
Explicitly set the .env file path for app loading.
Sourcepub fn with_env_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_env_prefix(self, prefix: impl Into<String>) -> Self
Override the env-var prefix for app loading.
Separator is always "__".
Sourcepub fn with_profile(self, profile: impl Into<String>) -> Self
pub fn with_profile(self, profile: impl Into<String>) -> Self
Set the configuration profile for app loading.
Loads config/profiles/{profile}.env before the main .env file. If an empty string is passed,
the profile name is read from the ENVIRONMENT environment variable during loading.
Sourcepub fn with_source(self, source: impl ConfigSource) -> Self
pub fn with_source(self, source: impl ConfigSource) -> Self
Add an adapter source.
In app loading, adapter sources are evaluated after files/dotenv and before process environment variables. In custom/TOML loading, adapter sources are evaluated after the primary file and before overrides.
Sourcepub fn with_override(
self,
key: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn with_override( self, key: impl Into<String>, value: impl Into<Value>, ) -> Self
Set a programmatic override value.
Overrides are loaded after all sources and have the highest precedence.
Sourcepub fn load<T>(&self) -> AppResult<T>where
T: DeserializeOwned,
pub fn load<T>(&self) -> AppResult<T>where
T: DeserializeOwned,
Load any typed config from this loader’s source policy.
This path does not run validation; the type only needs to be Deserialize.
Use ConfigLoader::load_validated to additionally run rskit_validation::Validate,
or ConfigLoader::load_app for the service-application convenience.
Sourcepub fn load_with<T>(&self, apply_defaults: impl FnOnce(&mut T)) -> AppResult<T>where
T: DeserializeOwned,
pub fn load_with<T>(&self, apply_defaults: impl FnOnce(&mut T)) -> AppResult<T>where
T: DeserializeOwned,
Load any typed config and apply programmatic defaults (no validation).
Sourcepub fn load_validated<T>(&self) -> AppResult<T>where
T: DeserializeOwned + Validate,
pub fn load_validated<T>(&self) -> AppResult<T>where
T: DeserializeOwned + Validate,
Load a typed config and run rskit_validation::Validate after decoding.
Sourcepub fn load_validated_with<T>(
&self,
apply_defaults: impl FnOnce(&mut T),
) -> AppResult<T>where
T: DeserializeOwned + Validate,
pub fn load_validated_with<T>(
&self,
apply_defaults: impl FnOnce(&mut T),
) -> AppResult<T>where
T: DeserializeOwned + Validate,
Load a typed config, apply programmatic defaults, then run validation.
Sourcepub fn load_app<T>(&self) -> AppResult<T>where
T: AppConfig,
pub fn load_app<T>(&self) -> AppResult<T>where
T: AppConfig,
Load an application/service config and call AppConfig::apply_defaults.
Applies defaults via AppConfig::apply_defaults, then runs validation.