Function get_many_unchecked

Source
pub unsafe fn get_many_unchecked<'de, Input>(
    json: Input,
    tree: &PointerTree,
) -> Result<Vec<Option<LazyValue<'de>>>>
where Input: JsonInput<'de>,
Expand description

get_many returns multiple fields from the PointerTree.

The result is a Result<Vec<Option<LazyValue>>>. The order of the Vec is same as the order of the tree.

If a key is unknown, the value at the corresponding position in Vec will be None. If json is invalid, or the field not be found, it will return a err.

§Safety

The JSON must be valid and well-formed, otherwise it may return unexpected result.

§Examples


let json = r#"
{"u": 123, "a": {"b" : {"c": [null, "found"]}}}"#;

// build a pointer tree, representing multiple json path
let mut tree = PointerTree::new();

tree.add_path(&["u"]);
tree.add_path(&["unknown_key"]);
tree.add_path(&pointer!["a", "b", "c", 1]);

let nodes = unsafe { sonic_rs::get_many_unchecked(json, &tree) };

match nodes {
    Ok(vals) => {
        assert_eq!(vals[0].as_ref().unwrap().as_raw_str(), "123");
        assert!(vals[1].is_none());
        assert_eq!(vals[2].as_ref().unwrap().as_raw_str(), "\"found\"");
    }
    Err(e) => {
        panic!("err: {:?}", e)
    }
}