sonic_rs

Function to_array_iter_unchecked

Source
pub unsafe fn to_array_iter_unchecked<'de, I: JsonInput<'de>>(
    json: I,
) -> ArrayJsonIter<'de> 
Expand description

Traverse the JSON text through a lazy object iterator. The JSON parsing will doing when iterating.

The item of the iterator is Result<LazyValue>.

§Errors

If the JSON is empty, or not a array, the result will be Err and the next() will return None.

§Safety

If the json is invalid, the result is undefined.

§Examples

use sonic_rs::JsonValueTrait;

for (i, ret) in unsafe { to_array_iter_unchecked(r#"[0, 1, 2, 3, 4, 5, 6]"#) }.enumerate() {
    let lv = ret.unwrap(); // get lazyvalue
    assert_eq!(i.to_string(), lv.as_raw_str()); // lv is not parsed
    assert_eq!(i, lv.as_u64().unwrap() as usize);
}

// the JSON is empty
for elem in unsafe { to_array_iter_unchecked("") } {
    assert!(elem.is_err());
}