Function jupiter::ig::yaml::list_to_doc
source · pub fn list_to_doc<F>(list: &[Yaml], key_filter: F) -> Result<Doc>
Expand description
Transforms the given list of YAML objects into a Doc.
The generated Doc will have a list 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_string: 'Test1'
---
a_string: 'Test2'
---
42
---
'text'
---
true
";
let yaml = &YamlLoader::load_from_str(input).unwrap();
let doc = list_to_doc(yaml, |_| true).unwrap();
assert_eq!(doc.root().len(), 6);
assert_eq!(doc.root().at(1).query("a_string").as_str().unwrap(), "Test1");
assert_eq!(doc.root().at(3).as_int().unwrap(), 42);
assert_eq!(doc.root().at(4).as_str().unwrap(), "text");
assert_eq!(doc.root().at(5).as_bool(), true);