Function jupiter::ig::yaml::hash_to_doc

source ·
pub fn hash_to_doc<F>(
    hash: &LinkedHashMap<Yaml, Yaml>,
    key_filter: F
) -> Result<Doc>
where F: Fn(&str) -> bool,
Expand description

Transforms a YAML hash (object) into a Doc.

The generated Doc will have an object as its root node. The filter lambda can be used to skip (ignore) certain keys (e.g. all starting with an underscore). If true is returned, the key is accepted, otherwise it is skipped.

§Errors

This will return an error if we’re running out of symbols (if there are more than 2^31-1 distinct keys in the hash or one of its children).

§Example

let input = "
a_string: 'Test'
a_map:
    inner_key: 42
a_list:
    - 1
    - 2
    - test: Plain String
a_bool: true        
";

let yaml = &YamlLoader::load_from_str(input).unwrap()[0];
let doc = hash_to_doc(yaml.as_hash().unwrap(), |_| true).unwrap();

assert_eq!(doc.root().query("a_string").as_str().unwrap(), "Test");