Skip to main content

AsyncStreamingEncoder

Struct AsyncStreamingEncoder 

Source
pub struct AsyncStreamingEncoder<W: AsyncWrite + Unpin> { /* private fields */ }
Available on crate features alloc and async-tokio only.
Expand description

An async streaming encoder for writing items incrementally.

Uses tokio’s async IO traits for non-blocking encoding operations.

§Example

use oxicode::streaming::AsyncStreamingEncoder;
use tokio::fs::File;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let file = File::create("output.bin").await?;
    let mut encoder = AsyncStreamingEncoder::new(file);

    for i in 0..1000u32 {
        encoder.write_item(&i).await?;
    }

    encoder.finish().await?;
    Ok(())
}

Implementations§

Source§

impl<W: AsyncWrite + Unpin> AsyncStreamingEncoder<W>

Source

pub fn new(writer: W) -> Self

Create a new async streaming encoder.

Source

pub fn with_config(writer: W, config: StreamingConfig) -> Self

Create an async streaming encoder with custom configuration.

Source

pub fn set_estimated_total(&mut self, total: u64)

Set the estimated total number of items (for progress reporting).

Source

pub async fn write_item<T: Encode>(&mut self, item: &T) -> Result<()>

Write a single item to the stream asynchronously.

Source

pub async fn write_all<T: Encode, I: IntoIterator<Item = T>>( &mut self, items: I, ) -> Result<()>

Write multiple items from an iterator asynchronously.

Source

pub async fn finish(self) -> Result<W>

Finish the stream, writing any remaining data and the end marker.

Source

pub fn progress(&self) -> &StreamingProgress

Get current progress.

Source

pub fn get_ref(&self) -> &W

Get a reference to the underlying writer.

Auto Trait Implementations§

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.