pub fn load<T: DeserializeOwned>(spec: &LoadSpec<'_>) -> Result<T, Error>Expand description
Reads and deserializes a configuration section.
This is what the generated load() calls. Missing files are skipped;
everything else — a parse failure, a missing required field, a value that
cannot become the requested type — is an Error naming the key path and
the source it came from.
§Errors
See ErrorKind for the categories.
§Example
use dynamic_config::{load, Format, LoadSpec, Source};
use serde::Deserialize;
#[derive(Deserialize)]
struct Server { port: u16 }
let sources = [Source::inline(r#"{"server": {"port": 8080}}"#, Format::Json)];
let server: Server = load(&LoadSpec::new("server", &sources).with_env("APP_"))
.expect("the inline document is well formed");
assert_eq!(server.port, 8080);