Trait AsyncReadRent

Source
pub trait AsyncReadRent {
    // Required methods
    fn read<T: IoBufMut>(
        &mut self,
        buf: T,
    ) -> impl Future<Output = BufResult<usize, T>>;
    fn readv<T: IoVecBufMut>(
        &mut self,
        buf: T,
    ) -> impl Future<Output = BufResult<usize, T>>;
}
Expand description

The AsyncReadRent trait defines asynchronous reading operations for objects that implement it.

It provides a way to read bytes from a source into a buffer asynchronously, which could be a file, socket, or any other byte-oriented stream.

Types that implement this trait are expected to manage asynchronous read operations, allowing them to interact with other asynchronous tasks without blocking the executor.

Required Methods§

Source

fn read<T: IoBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Reads bytes from this source into the provided buffer, returning the number of bytes read.

§Return

When this method returns (Ok(n), buf), it guarantees that 0 <= n <= buf.len(). A non-zero n means the buffer buf has been filled with n bytes of data from this source. If n is 0, it can indicate one of two possibilities:

  1. The reader has likely reached the end of the file and may not produce more bytes, though it is not certain that no more bytes will ever be produced.
  2. The provided buffer was 0 bytes in length.
§Errors

If an I/O or other error occurs, an error variant will be returned, ensuring that no bytes were read.

Source

fn readv<T: IoVecBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Similar to read, but reads data into a slice of buffers.

Data is copied sequentially into each buffer, with the last buffer potentially being only partially filled. This method should behave equivalently to a single call to read with the buffers concatenated.

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.

Implementations on Foreign Types§

Source§

impl AsyncReadRent for &[u8]

Source§

fn read<T: IoBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn readv<T: IoVecBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

impl AsyncReadRent for &mut [u8]

Source§

fn read<T: IoBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn readv<T: IoVecBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

impl<A: ?Sized + AsyncReadRent> AsyncReadRent for &mut A

Source§

fn read<T: IoBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn readv<T: IoVecBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

impl<T: AsRef<[u8]>> AsyncReadRent for Cursor<T>

Source§

async fn read<B: IoBufMut>(&mut self, buf: B) -> BufResult<usize, B>

Source§

async fn readv<B: IoVecBufMut>(&mut self, buf: B) -> BufResult<usize, B>

Source§

impl<T: ?Sized + AsyncReadRent> AsyncReadRent for Box<T>

Source§

fn read<B: IoBufMut>( &mut self, buf: B, ) -> impl Future<Output = BufResult<usize, B>>

Source§

fn readv<B: IoVecBufMut>( &mut self, buf: B, ) -> impl Future<Output = BufResult<usize, B>>

Implementors§