Skip to main content

Module config

Module config 

Source
Expand description

Config management types for #[derive(Config)].

Provides the Config trait, ConfigSource enum, ConfigError, and ConfigFieldMeta for runtime introspection. The proc macro generates implementations of Config for user-defined structs; this module supplies the interface those implementations depend on.

§Source precedence

Sources are applied in the order they appear in the slice passed to Config::load. Later sources win over earlier ones. The conventional order is: defaults first, then file, then environment, then CLI overrides (highest priority). #[derive(Config)] uses the same order when it calls load internally.

§Example

use server_less_core::config::{Config, ConfigSource};

#[derive(Config)]
struct AppConfig {
    #[param(default = "localhost")]
    host: String,
    #[param(default = 8080)]
    port: u16,
    #[param(env = "DATABASE_URL")]
    database_url: String,
}

let cfg = AppConfig::load(&[
    ConfigSource::Defaults,
    ConfigSource::File("app.toml".into()),
    ConfigSource::Env { prefix: Some("APP".into()) },
])?;

Structs§

ConfigFieldMeta
Metadata about a single field in a Config-implementing struct.

Enums§

ConfigError
Error returned by Config::load.
ConfigSource
Specifies where configuration values should be loaded from.

Traits§

Config
Trait implemented by #[derive(Config)] structs.

Functions§

load_toml_file
Read a TOML file and return its top-level keys as a flat string map.
load_toml_file_raw
Read a TOML file and return the parsed toml::Value (without flattening).