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
use crate::{Result, Settings};
/// Represents a [configuration provider](crate::Provider) for in-memory data.
#[derive(Debug, Default)]
pub struct Provider {
/// Gets a list of key/value pairs representing the initial data.
pub data: Vec<(String, String)>,
}
impl Provider {
/// Initializes a new in-memory configuration provider.
///
/// # Arguments
///
/// * `data` - The list of key/value pairs representing the initial data
pub fn new<S: AsRef<str>>(data: &[(S, S)]) -> Self {
Self {
data: data
.iter()
.map(|t| (t.0.as_ref().to_owned(), t.1.as_ref().to_owned()))
.collect(),
}
}
}
impl crate::Provider for Provider {
#[inline]
fn name(&self) -> &str {
"Memory"
}
fn load(&self, settings: &mut Settings) -> Result {
for (key, value) in &self.data {
settings.insert(key.clone(), value.clone());
}
Ok(())
}
}