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 new() -> ConfigLoader
pub fn new() -> ConfigLoader
Create an application/service loader.
Sourcepub fn app() -> ConfigLoader
pub fn app() -> ConfigLoader
Create an application/service loader.
Sourcepub fn toml(path: impl Into<PathBuf>) -> ConfigLoader
pub fn toml(path: impl Into<PathBuf>) -> ConfigLoader
Create a deterministic single-TOML loader.
This policy does not read dotenv files or process environment variables.
Sourcepub fn custom() -> ConfigLoader
pub fn custom() -> ConfigLoader
Create a loader with no implicit sources.
Sourcepub fn with_default(
self,
key: impl Into<String>,
value: impl Into<Value>,
) -> ConfigLoader
pub fn with_default( self, key: impl Into<String>, value: impl Into<Value>, ) -> ConfigLoader
Set a programmatic default value.
Defaults are loaded before all configured sources.
Sourcepub fn with_config_file(self, path: impl Into<PathBuf>) -> ConfigLoader
pub fn with_config_file(self, path: impl Into<PathBuf>) -> ConfigLoader
Explicitly set the TOML config file path for app loading.
Sourcepub fn with_env_file(self, path: impl Into<PathBuf>) -> ConfigLoader
pub fn with_env_file(self, path: impl Into<PathBuf>) -> ConfigLoader
Explicitly set the .env file path for app loading.
Sourcepub fn with_env_prefix(self, prefix: impl Into<String>) -> ConfigLoader
pub fn with_env_prefix(self, prefix: impl Into<String>) -> ConfigLoader
Override the env-var prefix for app loading.
Separator is always "__".
Sourcepub fn with_profile(self, profile: impl Into<String>) -> ConfigLoader
pub fn with_profile(self, profile: impl Into<String>) -> ConfigLoader
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) -> ConfigLoader
pub fn with_source(self, source: impl ConfigSource) -> ConfigLoader
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>,
) -> ConfigLoader
pub fn with_override( self, key: impl Into<String>, value: impl Into<Value>, ) -> ConfigLoader
Set a programmatic override value.
Overrides are loaded after all sources and have the highest precedence.
Sourcepub fn load<T>(&self) -> Result<T, AppError>where
T: DeserializeOwned,
pub fn load<T>(&self) -> Result<T, AppError>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),
) -> Result<T, AppError>where
T: DeserializeOwned,
pub fn load_with<T>(
&self,
apply_defaults: impl FnOnce(&mut T),
) -> Result<T, AppError>where
T: DeserializeOwned,
Load any typed config and apply programmatic defaults (no validation).
Sourcepub fn load_validated<T>(&self) -> Result<T, AppError>where
T: DeserializeOwned + Validate,
pub fn load_validated<T>(&self) -> Result<T, AppError>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),
) -> Result<T, AppError>where
T: DeserializeOwned + Validate,
pub fn load_validated_with<T>(
&self,
apply_defaults: impl FnOnce(&mut T),
) -> Result<T, AppError>where
T: DeserializeOwned + Validate,
Load a typed config, apply programmatic defaults, then run validation.
Sourcepub fn load_app<T>(&self) -> Result<T, AppError>where
T: AppConfig,
pub fn load_app<T>(&self) -> Result<T, AppError>where
T: AppConfig,
Load an application/service config and call AppConfig::apply_defaults.
Applies defaults via AppConfig::apply_defaults, then runs validation.
Trait Implementations§
Source§impl Debug for ConfigLoader
impl Debug for ConfigLoader
Source§impl Default for ConfigLoader
impl Default for ConfigLoader
Source§fn default() -> ConfigLoader
fn default() -> ConfigLoader
Auto Trait Implementations§
impl !RefUnwindSafe for ConfigLoader
impl !UnwindSafe for ConfigLoader
impl Freeze for ConfigLoader
impl Send for ConfigLoader
impl Sync for ConfigLoader
impl Unpin for ConfigLoader
impl UnsafeUnpin for ConfigLoader
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request