Struct dbn::encode::json::AsyncEncoder

source ·
pub struct AsyncEncoder<W>where
    W: AsyncWriteExt + Unpin,{ /* private fields */ }
Available on crate feature async only.
Expand description

Type for encoding files and streams of DBN records in newline-delimited JSON (ndjson).

Implementations§

source§

impl<W> Encoder<W>where W: AsyncWriteExt + Unpin,

source

pub fn new( writer: W, should_pretty_print: bool, use_pretty_px: bool, use_pretty_ts: bool ) -> Self

Creates a new instance of Encoder. If should_pretty_print is true, each JSON object will be nicely formatted and indented, instead of the default compact output with no whitespace between key-value pairs.

source

pub async fn encode_metadata(&mut self, metadata: &Metadata) -> Result<()>

Encodes metadata into JSON.

Errors

This function returns an error if there’s an error writing to writer.

Cancel safety

This method is not cancellation safe. If the method is used in tokio::select! statement and another branch completes first, then the metadata JSON may have been partially written, but future calls will begin writing the metadata JSON from the beginning.

source

pub fn get_ref(&self) -> &W

Returns a reference to the underlying writer.

source

pub fn get_mut(&mut self) -> &mut W

Returns a mutable reference to the underlying writer.

source

pub async fn encode_record<R: DbnEncodable>(&mut self, record: &R) -> Result<()>

Encode a single DBN record of type R.

Errors

This function returns an error if it’s unable to write to the underlying writer.

Cancel safety

This method is not cancellation safe. If the method is used in tokio::select! statement and another branch completes first, then the record may have been partially written, but future calls will begin writing the encoded record from the beginning.

source

pub async unsafe fn encode_record_ref( &mut self, record_ref: RecordRef<'_>, ts_out: bool ) -> Result<()>

Encodes a single DBN record.

Safety

ts_out must be false if record does not have an appended `ts_out

Errors

This function returns an error if it’s unable to write to the underlying writer or there’s a serialization error.

source

pub async fn flush(&mut self) -> Result<()>

Flushes any buffered content to the true output.

Errors

This function returns an error if it’s unable to flush the underlying writer.

Auto Trait Implementations§

§

impl<W> RefUnwindSafe for Encoder<W>where W: RefUnwindSafe,

§

impl<W> Send for Encoder<W>where W: Send,

§

impl<W> Sync for Encoder<W>where W: Sync,

§

impl<W> Unpin for Encoder<W>

§

impl<W> UnwindSafe for Encoder<W>where W: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> Ungil for Twhere T: Send,