1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::any::type_name;
use tokens::ChangeToken;

/// Defines the behavior of an object that provides configuration key/values for an application.
pub trait ConfigurationProvider {
    /// Gets the name of the provider.
    fn name(&self) -> &str {
        type_name::<Self>()
    }

    /// Attempts to get a configuration value with the specified key.
    ///
    /// # Arguments
    ///
    /// * `key` - The key of the value to retrieve
    fn get(&self, key: &str) -> Option<&str>;

    /// Returns a change token if this provider supports change tracking.
    fn reload_token(&self) -> Option<Box<dyn ChangeToken>> {
        None
    }

    /// Loads the configuration values from the implemented source.
    fn load(&mut self) {}

    /// Gets the immediate descendent configuration keys for a given parent path based on this
    /// [provider](trait.ConfigurationProvider.html) and the set of keys returned by all of
    /// the preceding [providers](trait.ConfigurationProvider.html).
    ///
    /// # Arguments
    ///
    /// * `earlier_keys` - The sequence of keys returned by preceding provider for the same parent path
    /// * `parent_path` - The optional parent path to evaluate
    fn child_keys(&self, earlier_keys: &mut Vec<String>, parent_path: Option<&str>);
}