Expand description
Adapter-oriented configuration loading with validation.
§Example
The end-to-end app example below exercises the validate-gated App API (AppConfig/ServiceConfig/Validate),
so it only compiles when the default validate feature is enabled.
use rskit_config::{AppConfig, ConfigLoader, SecretString, ServiceConfig};
use rskit_validation::Validate; use serde::Deserialize;
#[derive(Debug, Deserialize)] struct MyConfig {
#[serde(flatten)]
service: ServiceConfig,
grpc_port: u16,
api_token: SecretString,
}
impl Validate for MyConfig {
fn validate(&self) -> Result<(), validator::ValidationErrors> {
self.service.validate()?;
if self.grpc_port == 0 {
let mut errors = validator::ValidationErrors::new();
errors.add("grpc_port", validator::ValidationError::new("range"));
return Err(errors);
}
Ok(())
}
}
impl AppConfig for MyConfig {
fn apply_defaults(&mut self) {
if self.grpc_port == 0 {
self.grpc_port = 50051;
}
}
fn service_config(&self) -> &ServiceConfig {
&self.service
}
}
let cfg: MyConfig = ConfigLoader::app()
.with_default("grpc_port", 50051_i64)
.with_env_prefix("MYAPP")
.load_app()?;
assert_eq!(cfg.api_token.to_string(), "***");Structs§
- Composite
Key - A
MergeIdentityover several fields, each addressed by a dotted path. - Config
Loader - Loads typed configuration from ordered source adapters.
- Config
MapSource - In-memory key/value config source.
- Dotenv
File Source - Dotenv file source.
- Environment
Source - Environment-variable configuration source.
- File
Config Sink - File-backed writable config store.
- Identity
Key - A simple
MergeIdentitynaming a single identity field directly. - InMemory
Config Sink - In-memory writable config store.
- Include
Merge - Identity-aware include-merge configuration.
- Logging
Config - Logging configuration.
- Secret
String - A string wrapper that prevents accidental secret exposure in logs or config dumps.
- Service
Config - Base service configuration — embed this in every application config.
- Strict
Loader - Strict, layered document loader.
- Toml
File Source - TOML file source.
Enums§
- Config
Change - A typed configuration change emitted by a
ConfigWatchsource. - Environment
- Deployment environment.
- LogFormat
- Log output format.
- LogOutput
- Where log output is written.
- Profile
- Profile environment-file selection.
Traits§
- AppConfig
- Trait that every application config struct must implement.
- Config
Sink - Adapter contract for writable configuration backends.
- Config
Source - Adapter contract for configuration sources.
- Config
Watch - Adapter contract for configuration backends that emit change notifications.
- Merge
Identity - Identity rule for an array-of-tables section during include-merge.
Functions§
- deserialize_
subtree - Deserialize a retained raw subtree into a concrete type.
- load_
config - Convenience function: create a default app loader and call
ConfigLoader::load_app. - load_
strict - Load a single strict file into
Twith no includes (decoded as TOML).
Type Aliases§
- Config
Change Stream - A bounded stream of
ConfigChangeevents. - Config
Table - Flat
key -> valuetable that backs aFileConfigSink. - RawTable
- A map of dynamic-keyed raw subtrees (for example
[ecosystems.<id>]). - RawValue
- A raw value retained verbatim for later, downstream parsing.