UninitAsyncReadExt

Trait UninitAsyncReadExt 

Source
pub trait UninitAsyncReadExt: UninitRead + AsyncRead {
    // Provided methods
    fn read_uninit<'buf>(
        &mut self,
        buf: &'buf mut [MaybeUninit<u8>],
    ) -> impl Future<Output = Result<&'buf [u8], Error>>
       where Self: Unpin { ... }
    fn read_uninit_exact<'buf>(
        &mut self,
        buf: &'buf mut [MaybeUninit<u8>],
    ) -> impl Future<Output = Result<&'buf [u8], Error>>
       where Self: Unpin { ... }
}
Expand description

An extension trait that provides convenience methods for asynchronous readers that implement UninitRead.

This trait is automatically implemented for any type that satisfies the bounds AsyncRead + UninitRead. It offers safe wrappers for reading directly into uninitialized buffers, abstracting away the underlying unsafe operations.

Provided Methods§

Source

fn read_uninit<'buf>( &mut self, buf: &'buf mut [MaybeUninit<u8>], ) -> impl Future<Output = Result<&'buf [u8], Error>>
where Self: Unpin,

Asynchronously pulls some bytes from this source into the provided uninitialized buffer.

This method is a wrapper around AsyncReadExt::read that accepts a slice of MaybeUninit<u8>, avoiding the need for the caller to perform unsafe operations.

On a successful read, this method returns a slice &[u8] that represents the portion of the buffer that was initialized by the read. The length of the returned slice is equivalent to the number of bytes read. An empty slice indicates EOF has been reached.

§Errors

This function will return an error if the underlying call to AsyncReadExt::read returns an error.

Source

fn read_uninit_exact<'buf>( &mut self, buf: &'buf mut [MaybeUninit<u8>], ) -> impl Future<Output = Result<&'buf [u8], Error>>
where Self: Unpin,

Asynchronously reads the exact number of bytes required to fill buf.

This method is a wrapper around AsyncReadExt::read_exact that accepts a slice of MaybeUninit<u8>, avoiding the need for the caller to perform unsafe operations.

On a successful read, this method returns a slice &[u8] that represents the entire buffer, now guaranteed to be fully initialized.

§Errors

This function will return an error if the underlying call to AsyncReadExt::read_exact returns an error. If an EOF is found before the buffer is filled, an error of kind std::io::ErrorKind::UnexpectedEof is returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§