Struct AsyncMapWriter

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

Source

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.

Source

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.

Source

pub fn into_inner(self) -> W

Consumes the AsyncMapWriter and returns the underlying writer.

Trait Implementations§

Source§

impl<W: AsyncWrite> AsyncWrite for AsyncMapWriter<'_, W>

Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to close the object. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
Source§

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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, W> AsyncMapWrite<'a, W> for W
where W: AsyncWrite,

Source§

fn map_with_capacity( self, process_fn: impl MapWriteFn + 'a, capacity: usize, ) -> AsyncMapWriter<'a, W>

Maps the data written to the writer using the provided function with a specified buffer capacity. Read more
Source§

fn map(self, process_fn: impl MapWriteFn + 'a) -> AsyncMapWriter<'a, W>
where Self: Sized,

Maps the data written to the writer using the provided function. Read more
Source§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

Source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>
where Self: Unpin,

Writes some bytes into the byte stream. Read more
Source§

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], ) -> WriteVectoredFuture<'a, Self>
where Self: Unpin,

Like write(), except that it writes a slice of buffers. Read more
Source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>
where Self: Unpin,

Writes an entire buffer into the byte stream. Read more
Source§

fn flush(&mut self) -> FlushFuture<'_, Self>
where Self: Unpin,

Flushes the stream to ensure that all buffered contents reach their destination. Read more
Source§

fn close(&mut self) -> CloseFuture<'_, Self>
where Self: Unpin,

Closes the writer. Read more
Source§

fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. 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.