configbuilder-pattern-loader 0.1.0

configbuilder-pattern: loader domain, trait contract + tech-agnostic reference implementation.
Documentation
use crate::{ConfigError, FeatureState, LoadedFeature};

/// Load optional TOML sections with configurable enable/disable precedence.
///
/// Unlike [`Loader`], which returns `T::default()` for absent sections,
/// `FeatureLoader` distinguishes absent (feature off) from present (feature on)
/// and enforces a three-level precedence chain:
///
/// ```text
/// env var  >  enabled = false  >  section presence  >  section absent
/// ```
///
/// [`Loader`]: crate::Loader
pub trait FeatureLoader {
    /// Load the section at `key` with full metadata.
    ///
    /// Applies the full precedence chain — env var override, explicit
    /// `enabled = false`, section presence — and records the reason in the
    /// returned [`LoadedFeature::record`].
    fn load_feature<T>(&self, key: &str) -> Result<LoadedFeature<T>, ConfigError>
    where
        T: serde::de::DeserializeOwned;

    /// Load the section at `key` as a `FeatureState`, without metadata.
    fn load_optional_section<T>(&self, key: &str) -> Result<FeatureState<T>, ConfigError>
    where
        T: serde::de::DeserializeOwned,
    {
        self.load_feature(key).map(|loaded| loaded.state)
    }
}