Expand description
figment provider integration. Pulls in figment 0.10
when the figment Cargo feature is enabled.
figment provider for noyalib YAML.
figment is the popular layered-configuration crate: it
merges multiple config sources (env vars, TOML / JSON / YAML
files, CLI flags, in-memory overrides) into a single typed
struct via Figment::new().merge(...).join(...).extract(). The
Yaml provider in this module plugs noyalib into that
chain the same way figment::providers::Toml /
figment::providers::Json do — without depending on the
unmaintained serde_yaml 0.9 crate.
Gated behind the figment Cargo feature.
§Examples
use figment::providers::Format;
use figment::Figment;
use noyalib::figment::Yaml;
#[derive(serde::Deserialize)]
struct Config {
name: String,
port: u16,
}
let yaml = "name: noyalib\nport: 8080\n";
let cfg: Config = Figment::new().merge(Yaml::string(yaml)).extract().unwrap();
assert_eq!(cfg.name, "noyalib");
assert_eq!(cfg.port, 8080);Layered example — start with defaults, override with a YAML file, finalise with environment variables:
ⓘ
use figment::Figment;
use figment::providers::{Env, Serialized};
use noyalib::figment::Yaml;
let cfg = Figment::new()
.merge(Serialized::defaults(MyDefaults::default()))
.merge(Yaml::file("config.yaml"))
.merge(Env::prefixed("MYAPP_"))
.extract::<MyConfig>()
.unwrap();Structs§
- Yaml
- Figment [
Format] for noyalib YAML. - Yaml
With Config - A figment [
Provider] for YAML parsed under a caller-suppliedParserConfig. Built byYaml::string_with_configorYaml::file_with_config.