Skip to main content

source_of

Function source_of 

Source
pub fn source_of(
    spec: &LoadSpec<'_>,
    path: &str,
) -> Result<Option<Origin>, Error>
Expand description

Where the value at path would come from, if anything supplies it.

This is the answer to the question every configuration bug starts with: which layer set this? It re-reads the sources, so it reports what the next load would see rather than what the current snapshot holds.

path is dotted and relative to the section, as in "pool.max_size".

§Errors

If a source cannot be read or parsed — the same failures as load.

§Example

use dynamic_config::{source_of, Format, LoadSpec, Origin, Source};

let sources = [Source::inline(r#"{"db": {"host": "localhost"}}"#, Format::Json)];
let spec = LoadSpec::new("db", &sources);

assert_eq!(source_of(&spec, "host").unwrap(), Some(Origin::Inline));
assert_eq!(source_of(&spec, "port").unwrap(), None);