rtb-config 0.6.5

Layered, typed configuration backed by figment. Part of the phpboyscout Rust toolkit.
Documentation
//! The YAML [`Format`] behind `Config`'s embedded defaults and user files.

use figment::providers::Format;
use serde::de::DeserializeOwned;
use serde_saphyr::{DuplicateKeyPolicy, MergeKeyPolicy};

/// YAML parsed by `serde-saphyr`, with the options pinned to the behaviour
/// figment's `serde_yaml`-backed provider had: YAML 1.2 booleans only, `<<`
/// as an ordinary key, and the last of two duplicate keys winning.
pub struct Yaml;

impl Format for Yaml {
    type Error = serde_saphyr::Error;

    const NAME: &'static str = "YAML";

    fn from_str<T: DeserializeOwned>(string: &str) -> Result<T, Self::Error> {
        serde_saphyr::from_str_with_options(
            string,
            serde_saphyr::options! {
                strict_booleans: true,
                merge_keys: MergeKeyPolicy::AsOrdinary,
                duplicate_keys: DuplicateKeyPolicy::LastWins,
                with_snippet: false,
            },
        )
    }
}