Skip to main content

Crate rskit_config

Crate rskit_config 

Source
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§

CompositeKey
A MergeIdentity over several fields, each addressed by a dotted path.
ConfigLoader
Loads typed configuration from ordered source adapters.
ConfigMapSource
In-memory key/value config source.
DotenvFileSource
Dotenv file source.
EnvironmentSource
Environment-variable configuration source.
FileConfigSink
File-backed writable config store.
IdentityKey
A simple MergeIdentity naming a single identity field directly.
InMemoryConfigSink
In-memory writable config store.
IncludeMerge
Identity-aware include-merge configuration.
LoggingConfig
Logging configuration.
SecretString
A string wrapper that prevents accidental secret exposure in logs or config dumps.
ServiceConfig
Base service configuration — embed this in every application config.
StrictLoader
Strict, layered document loader.
TomlFileSource
TOML file source.

Enums§

ConfigChange
A typed configuration change emitted by a ConfigWatch source.
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.
ConfigSink
Adapter contract for writable configuration backends.
ConfigSource
Adapter contract for configuration sources.
ConfigWatch
Adapter contract for configuration backends that emit change notifications.
MergeIdentity
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 T with no includes (decoded as TOML).

Type Aliases§

ConfigChangeStream
A bounded stream of ConfigChange events.
ConfigTable
Flat key -> value table that backs a FileConfigSink.
RawTable
A map of dynamic-keyed raw subtrees (for example [ecosystems.<id>]).
RawValue
A raw value retained verbatim for later, downstream parsing.