Function from_fallible_iter

Source
pub fn from_fallible_iter<T, I>(
    into_iter: I,
) -> FallibleNdjsonIter<T, I::IntoIter> 
where I: IntoIterator,
Available on crate feature iter only.
Expand description

Wraps an iterator of Results of data blocks, i.e. types implementing AsBytes, obtained by IntoIterator::into_iter on into_iter and offers an Iterator implementation over parsed NDJSON-records according to Deserialize. Errors in the wrapped iterator are forwarded via FallibleNdjsonError::InputError, while parsing errors are indicated via FallibleNdjsonError::JsonError. The parser is configured with the default NdjsonConfig.

§Example

use ndjson_stream::fallible::FallibleNdjsonError;

let data_block_results = vec![
    Ok("123\n"),
    Err("some error"),
    Ok("456\n789\n")
];

let mut ndjson_iter = ndjson_stream::from_fallible_iter::<u32, _>(data_block_results);

assert!(matches!(ndjson_iter.next(), Some(Ok(123))));
assert!(matches!(ndjson_iter.next(), Some(Err(FallibleNdjsonError::InputError("some error")))));
assert!(matches!(ndjson_iter.next(), Some(Ok(456))));
assert!(matches!(ndjson_iter.next(), Some(Ok(789))));
assert!(ndjson_iter.next().is_none());