config/builder.rs
1use crate::{ConfigurationRoot, ConfigurationSource, ReloadError};
2use std::any::Any;
3use std::collections::HashMap;
4
5/// Defines the behavior used to build an application [`Configuration`](crate::Configuration).
6pub trait ConfigurationBuilder {
7 /// Gets a read-only key/value collection that can be used to share data between the
8 /// [`ConfigurationBuilder`] and each registered [`ConfigurationSource`](crate::ConfigurationSource).
9 fn properties(&self) -> &HashMap<String, Box<dyn Any>>;
10
11 /// Gets the registered [`ConfigurationSource`](crate::ConfigurationSource) set used to obtain
12 /// configuration values.
13 fn sources(&self) -> &[Box<dyn ConfigurationSource>];
14
15 /// Adds a new configuration source.
16 ///
17 /// # Arguments
18 ///
19 /// * `source` - The [`ConfigurationSource`](crate::ConfigurationSource) to add
20 fn add(&mut self, source: Box<dyn ConfigurationSource>);
21
22 /// Builds [`ConfigurationRoot`](crate::ConfigurationRoot) with the keys and values from the
23 /// registered [`ConfigurationSource`](crate::ConfigurationSource) set.
24 fn build(&self) -> Result<Box<dyn ConfigurationRoot>, ReloadError>;
25}