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>
impl<W: AsyncWrite + Unpin> AsyncStreamingEncoder<W>
Sourcepub fn with_config(writer: W, config: StreamingConfig) -> Self
pub fn with_config(writer: W, config: StreamingConfig) -> Self
Create an async streaming encoder with custom configuration.
Sourcepub fn set_estimated_total(&mut self, total: u64)
pub fn set_estimated_total(&mut self, total: u64)
Set the estimated total number of items (for progress reporting).
Sourcepub async fn write_item<T: Encode>(&mut self, item: &T) -> Result<()>
pub async fn write_item<T: Encode>(&mut self, item: &T) -> Result<()>
Write a single item to the stream asynchronously.
Sourcepub async fn write_all<T: Encode, I: IntoIterator<Item = T>>(
&mut self,
items: I,
) -> Result<()>
pub async fn write_all<T: Encode, I: IntoIterator<Item = T>>( &mut self, items: I, ) -> Result<()>
Write multiple items from an iterator asynchronously.
Sourcepub async fn finish(self) -> Result<W>
pub async fn finish(self) -> Result<W>
Finish the stream, writing any remaining data and the end marker.
Sourcepub fn progress(&self) -> &StreamingProgress
pub fn progress(&self) -> &StreamingProgress
Get current progress.
Auto Trait Implementations§
impl<W> Freeze for AsyncStreamingEncoder<W>where
W: Freeze,
impl<W> RefUnwindSafe for AsyncStreamingEncoder<W>where
W: RefUnwindSafe,
impl<W> Send for AsyncStreamingEncoder<W>where
W: Send,
impl<W> Sync for AsyncStreamingEncoder<W>where
W: Sync,
impl<W> Unpin for AsyncStreamingEncoder<W>
impl<W> UnsafeUnpin for AsyncStreamingEncoder<W>where
W: UnsafeUnpin,
impl<W> UnwindSafe for AsyncStreamingEncoder<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more