Trait digger::Dig[][src]

pub trait Dig {
    fn value_for_name(&self, name: &str) -> Option<&Self>;

    fn dig(&self, selector: impl AsRef<str>) -> Option<&Self> { ... }
}
Expand description

Used to “dig through” recursive data structures to extract named values using a selector string. Selectors are sequential names separated by an ASCII ‘.’ character, optionally prefixed with a ‘$’ root segment.

Examples

When the serde_json feature is enabled, Value implements Dig:

let value = json!({
    "foo": {
        "bar": {
            "baz": "hello there"
        }
    }
});

let expected = Value::String(String::from("hello there"));

assert_eq!(value.dig("foo.bar.baz"), Some(&expected));

Required methods

Retrieves a datum identified by the given name segment, or none.

Provided methods

Fetches the data within self identified by the given selector.

Selector strings have a lightweight syntax resembling basic JSON-Path selectors - chains of name segments, separated by ASCII period characters (.). As in JSON Path, selectors can be absolute (i.e. prefixed with a sigil, like $.) or relative.

Returns an optional result, containing a reference to the named data if found, and none if not.

Implementations on Foreign Types

Implementors