pub fn from_stream<T, S>(bytes_stream: S) -> NdjsonStream<T, S>
Available on crate feature
stream
only.Expand description
Wraps a Stream of data blocks, i.e. types implementing AsBytes, and offers a Stream implementation over parsed NDJSON-records according to Deserialize. The parser is configured with the default NdjsonConfig.
ยงExample
use futures::stream::{self, StreamExt};
let data_blocks = vec![
"123\n",
"456\n789\n"
];
let mut ndjson_stream = ndjson_stream::from_stream::<u32, _>(stream::iter(data_blocks));
tokio_test::block_on(async {
assert!(matches!(ndjson_stream.next().await, Some(Ok(123))));
assert!(matches!(ndjson_stream.next().await, Some(Ok(456))));
assert!(matches!(ndjson_stream.next().await, Some(Ok(789))));
assert!(ndjson_stream.next().await.is_none());
});