pub struct AsyncMapWriter<'a, W> { /* private fields */ }
Expand description
A wrapper around an AsyncWrite
that allows for data processing
before the actual I/O operation.
This struct buffers the data written to the underlying writer and applies a mapping function to the data before writing it out. It is designed to optimize writes by using a buffer of a specified size (default is 8KB).
The buffer size also acts as a threshold for the length of data passed to the mapping function, and will be gauranteed to be equal to or less than the specified capacity, unless the function modifies the buffer capacity itself.
Implementations§
Source§impl<'a, W: AsyncWrite> AsyncMapWriter<'a, W>
impl<'a, W: AsyncWrite> AsyncMapWriter<'a, W>
Sourcepub fn new(writer: W, process_fn: impl MapWriteFn + 'a) -> Self
pub fn new(writer: W, process_fn: impl MapWriteFn + 'a) -> Self
Creates a new AsyncMapWriter
with a default buffer size of 8KB.
This function initializes the writer with the provided process_fn
to map the data before writing.
Sourcepub fn with_capacity(
writer: W,
process_fn: impl MapWriteFn + 'a,
capacity: usize,
) -> Self
pub fn with_capacity( writer: W, process_fn: impl MapWriteFn + 'a, capacity: usize, ) -> Self
Creates a new AsyncMapWriter
with a specified buffer capacity.
This function initializes the writer with the provided process_fn
to map the data before writing.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Consumes the AsyncMapWriter
and returns the underlying writer.
Trait Implementations§
Source§impl<W: AsyncWrite> AsyncWrite for AsyncMapWriter<'_, W>
impl<W: AsyncWrite> AsyncWrite for AsyncMapWriter<'_, W>
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf
into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
impl<'__pin, 'a, W> Unpin for AsyncMapWriter<'a, W>where
PinnedFieldsOf<__Origin<'__pin, 'a, W>>: Unpin,
Auto Trait Implementations§
impl<'a, W> Freeze for AsyncMapWriter<'a, W>where
W: Freeze,
impl<'a, W> !RefUnwindSafe for AsyncMapWriter<'a, W>
impl<'a, W> !Send for AsyncMapWriter<'a, W>
impl<'a, W> !Sync for AsyncMapWriter<'a, W>
impl<'a, W> !UnwindSafe for AsyncMapWriter<'a, W>
Blanket Implementations§
Source§impl<'a, W> AsyncMapWrite<'a, W> for Wwhere
W: AsyncWrite,
impl<'a, W> AsyncMapWrite<'a, W> for Wwhere
W: AsyncWrite,
Source§fn map_with_capacity(
self,
process_fn: impl MapWriteFn + 'a,
capacity: usize,
) -> AsyncMapWriter<'a, W>
fn map_with_capacity( self, process_fn: impl MapWriteFn + 'a, capacity: usize, ) -> AsyncMapWriter<'a, W>
Source§fn map(self, process_fn: impl MapWriteFn + 'a) -> AsyncMapWriter<'a, W>where
Self: Sized,
fn map(self, process_fn: impl MapWriteFn + 'a) -> AsyncMapWriter<'a, W>where
Self: Sized,
Source§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
Source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>where
Self: Unpin,
Source§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectoredFuture<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectoredFuture<'a, Self>where
Self: Unpin,
Source§fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>where
Self: Unpin,
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>where
Self: Unpin,
Source§fn flush(&mut self) -> FlushFuture<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self>where
Self: Unpin,
Source§fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
dyn AsyncWrite + Send + 'a
. Read more