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§
- Config
Field Meta - Metadata about a single field in a
Config-implementing struct.
Enums§
- Config
Error - Error returned by
Config::load. - Config
Source - 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).