configbuilder_pattern_loader/feature_registry_ops.rs
1use crate::{
2 ConfigError, DefaultLoader, FeatureRecord, FeatureState, FeatureSummary, OptionalSection,
3};
4
5/// Startup feature registry: collection, dependency validation, and observation.
6///
7/// Implemented by [`crate::FeatureRegistry`].
8pub trait FeatureRegistryOps: Sized {
9 /// Create an empty registry.
10 fn new() -> Self;
11
12 /// Register a callback to observe loaded records.
13 fn on_load(&mut self, observer: impl Fn(&FeatureRecord) + 'static);
14
15 /// Load a feature section and record its state.
16 ///
17 /// # Errors
18 ///
19 /// Propagates any [`ConfigError`] returned by the loader.
20 fn load<T>(&mut self, loader: &DefaultLoader) -> Result<FeatureState<T>, ConfigError>
21 where
22 T: OptionalSection;
23
24 /// Validate that every enabled feature's declared dependencies are enabled.
25 ///
26 /// # Errors
27 ///
28 /// Returns [`ConfigError::Validation`] listing all unsatisfied dependencies.
29 fn validate_dependencies(&self) -> Result<(), ConfigError>;
30
31 /// Borrow the recorded feature records.
32 fn records(&self) -> &[FeatureRecord];
33
34 /// Build a point-in-time snapshot of the recorded features.
35 fn summary(&self) -> FeatureSummary;
36}