pub struct NdjsonEngine<T> { /* private fields */ }
Expand description
The low-level engine parsing NDJSON-data given as byte slices into objects of the type parameter
T
. Data is supplied in chunks and parsed objects can subsequently be read from a queue.
Users of this crate should usually not have to use this struct but rather a higher-level interface such as iterators.
Implementations§
Source§impl<T> NdjsonEngine<T>
impl<T> NdjsonEngine<T>
Sourcepub fn new() -> NdjsonEngine<T>
pub fn new() -> NdjsonEngine<T>
Creates a new NDJSON-engine for objects of the given type parameter with default NdjsonConfig.
Sourcepub fn with_config(config: NdjsonConfig) -> NdjsonEngine<T>
pub fn with_config(config: NdjsonConfig) -> NdjsonEngine<T>
Creates a new NDJSON-engine for objects of the given type parameter with the given NdjsonConfig to control its behavior. See NdjsonConfig for more details.
Sourcepub fn pop(&mut self) -> Option<JsonResult<T>>
pub fn pop(&mut self) -> Option<JsonResult<T>>
Reads the next element from the queue of parsed items, if sufficient NDJSON-data has been
supplied previously via NdjsonEngine::input, that is, a newline character has been
observed. If the input until the newline is not valid JSON, the parse error is returned. If
no element is available in the queue, None
is returned.
Source§impl<T> NdjsonEngine<T>where
for<'deserialize> T: Deserialize<'deserialize>,
impl<T> NdjsonEngine<T>where
for<'deserialize> T: Deserialize<'deserialize>,
Sourcepub fn input(&mut self, data: impl AsBytes)
pub fn input(&mut self, data: impl AsBytes)
Parses the given data as NDJSON. In case the end does not match up with a newline, the rest is stored in an internal cache. Consequently, the rest from a previous call to this method is prepended to the given data in case a newline is encountered.
Sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
Parses the rest leftover from previous calls to NdjsonEngine::input, i.e. the data after the last given newline character, if all of the following conditions are met.
- The engine uses a config with NdjsonConfig::with_parse_rest set to
true
. - There is non-empty data left to parse. In other words, the previous provided input did not end with a newline character.
- The rest is not considered empty by the handling configured in NdjsonConfig::with_empty_line_handling. That is, if the rest consists only of whitespace and EmptyLineHandling::IgnoreBlank is used, the rest is not parsed.
In any case, the rest is discarded from the input buffer. Therefore, this function is idempotent.
Note: This function is intended to be called after the input ended, but there is no validation in place to check that NdjsonEngine::input is not called afterwards. Doing this anyway may lead to unexpected behavior, as JSON-lines may be partially discarded.