Trait encrypt_config::Source
source · pub trait Source {
type Value: Serialize + DeserializeOwned;
type Map: IntoIterator<Item = (String, Self::Value)>;
// Required method
fn default(&self) -> Result<Self::Map, Box<dyn Error>>;
}Expand description
A trait for normal config source that is neither encrypted or persisted.
Example
use encrypt_config::{Config, Source};
#[cfg(feature = "secret")]
let mut config = Config::new("test");
#[cfg(not(feature = "secret"))]
let mut config = Config::new();
struct NormalSource;
impl Source for NormalSource {
type Value = String;
type Map = Vec<(String, Self::Value)>;
fn default(&self) -> Result<Self::Map, Box<dyn std::error::Error>> {
Ok(vec![("key".to_owned(), "value".to_owned())])
}
}
config.add_source(NormalSource).unwrap();
let v: String = config.get("key").unwrap();
assert_eq!(v, "value");Required Associated Types§
sourcetype Value: Serialize + DeserializeOwned
type Value: Serialize + DeserializeOwned
The type of the config value
sourcetype Map: IntoIterator<Item = (String, Self::Value)>
type Map: IntoIterator<Item = (String, Self::Value)>
The type of the config map. It must be iterable, the first item of the tuple is the key, which should be String only.