Struct NdjsonEngine

Source
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>

Source

pub fn new() -> NdjsonEngine<T>

Creates a new NDJSON-engine for objects of the given type parameter with default NdjsonConfig.

Source

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.

Source

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>,

Source

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.

Source

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.

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.

Trait Implementations§

Source§

impl<T> Default for NdjsonEngine<T>

Source§

fn default() -> NdjsonEngine<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for NdjsonEngine<T>

§

impl<T> !RefUnwindSafe for NdjsonEngine<T>

§

impl<T> Send for NdjsonEngine<T>
where T: Send,

§

impl<T> Sync for NdjsonEngine<T>
where T: Sync,

§

impl<T> Unpin for NdjsonEngine<T>
where T: Unpin,

§

impl<T> !UnwindSafe for NdjsonEngine<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.