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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
extern crate caseless;
extern crate slog;
use std::collections::HashSet;
use std::ops::Deref;
pub use config::ConfigBuilder;
pub use provider::{ConfigurationProviderBuilder, DefaultConfigurationProvider};
pub use strings::ConfigKey;
pub use values::Settings;
pub trait LogOwner {
fn logger(&self) -> &slog::Logger;
}
pub trait Configuration: Sized + Send + Sync + Clone {
type Section: ConfigurationSection;
type Sections: Iterator<Item = Self::Section>;
fn get<K: Into<ConfigKey>>(&self, key: K) -> Option<&str>;
fn get_section<K: Into<ConfigKey>>(&self, key: K) -> Self::Section;
fn sections(&self) -> Self::Sections;
}
pub trait ConfigurationSection: Configuration {
fn key(&self) -> &ConfigKey;
fn path(&self) -> &ConfigKey;
fn value(&self) -> Option<&str>;
}
pub trait ConfigurationProvider: Send + Sync {
fn try_get(&self, key: &ConfigKey) -> Option<&str>;
fn get_child_keys(&self, key: &ConfigKey, keys: &mut HashSet<ConfigKey>);
}
impl<P: ConfigurationProvider> ConfigurationProvider for Box<P> {
fn try_get(&self, key: &ConfigKey) -> Option<&str> {
self.deref().try_get(key)
}
fn get_child_keys(&self, key: &ConfigKey, keys: &mut HashSet<ConfigKey>) {
self.deref().get_child_keys(key, keys)
}
}
impl ConfigurationProvider for Box<dyn ConfigurationProvider> {
fn try_get(&self, key: &ConfigKey) -> Option<&str> {
self.deref().try_get(key)
}
fn get_child_keys(&self, key: &ConfigKey, keys: &mut HashSet<ConfigKey>) {
self.deref().get_child_keys(key, keys)
}
}
pub trait ConfigurationSource {
fn build<B: ConfigurationBuilder>(self, builder: B) -> std::io::Result<B>;
}
pub trait ConfigurationBuilder: Sized {
type Config: Configuration;
fn push_provider<P: ConfigurationProvider + 'static>(self, source: P) -> Self;
fn add<S: ConfigurationSource>(self, source: S) -> std::io::Result<Self> {
source.build(self)
}
fn build(self) -> std::io::Result<Self::Config>;
}
mod config;
mod provider;
mod strings;
mod values;