Skip to main content

RecvStream

Trait RecvStream 

Source
pub trait RecvStream: MaybeSend {
    type Error: Error;

    // Required methods
    fn read(
        &mut self,
        dst: &mut [u8],
    ) -> impl Future<Output = Result<Option<usize>, Self::Error>> + MaybeSend;
    fn stop(&mut self, code: u32);
    fn closed(
        &mut self,
    ) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend;

    // Provided methods
    fn read_buf<B: BufMut + MaybeSend>(
        &mut self,
        buf: &mut B,
    ) -> impl Future<Output = Result<Option<usize>, Self::Error>> + MaybeSend { ... }
    fn read_chunk(
        &mut self,
        max: usize,
    ) -> impl Future<Output = Result<Option<Bytes>, Self::Error>> + MaybeSend { ... }
    fn read_all(
        &mut self,
    ) -> impl Future<Output = Result<Bytes, Self::Error>> + MaybeSend { ... }
    fn read_all_buf<B: BufMut + MaybeSend>(
        &mut self,
        buf: &mut B,
    ) -> impl Future<Output = Result<usize, Self::Error>> + MaybeSend { ... }
}
Expand description

An incoming stream of bytes from the peer.

All bytes are flushed in order and the stream is flow controlled. The stream is closed with STOP_SENDING code=0 when dropped.

Required Associated Types§

Source

type Error: Error

Error type returned by receive-side stream operations.

Required Methods§

Source

fn read( &mut self, dst: &mut [u8], ) -> impl Future<Output = Result<Option<usize>, Self::Error>> + MaybeSend

Read the next chunk of data, up to the max size.

This returns a chunk of data instead of copying, which can be more efficient.

Source

fn stop(&mut self, code: u32)

Send a STOP_SENDING QUIC code, informing the peer that no more data will be read.

Implementations must do this on drop to avoid leaking flow control. Call this method manually to specify a custom code.

Source

fn closed( &mut self, ) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend

Block until the stream has been closed by either side.

This includes:

Provided Methods§

Source

fn read_buf<B: BufMut + MaybeSend>( &mut self, buf: &mut B, ) -> impl Future<Output = Result<Option<usize>, Self::Error>> + MaybeSend

Read some data into the provided buffer.

The number of bytes read is returned, or None if the stream is closed. The buffer is advanced by the number of bytes read.

Source

fn read_chunk( &mut self, max: usize, ) -> impl Future<Output = Result<Option<Bytes>, Self::Error>> + MaybeSend

Read the next chunk of data, up to the max size.

This returns a chunk of data instead of copying, which can be more efficient.

Source

fn read_all( &mut self, ) -> impl Future<Output = Result<Bytes, Self::Error>> + MaybeSend

Helper to keep reading until the stream is closed.

Source

fn read_all_buf<B: BufMut + MaybeSend>( &mut self, buf: &mut B, ) -> impl Future<Output = Result<usize, Self::Error>> + MaybeSend

Helper to keep reading until the buffer is full.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§