Skip to main content

SendStream

Trait SendStream 

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

    // Required methods
    fn write(
        &mut self,
        buf: &[u8],
    ) -> impl Future<Output = Result<usize, Self::Error>> + MaybeSend;
    fn set_priority(&mut self, order: u8);
    fn finish(&mut self) -> Result<(), Self::Error>;
    fn reset(&mut self, code: u32);
    fn closed(
        &mut self,
    ) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend;

    // Provided methods
    fn write_buf<B: Buf + MaybeSend>(
        &mut self,
        buf: &mut B,
    ) -> impl Future<Output = Result<usize, Self::Error>> + MaybeSend { ... }
    fn write_chunk(
        &mut self,
        chunk: Bytes,
    ) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend { ... }
    fn write_all(
        &mut self,
        buf: &[u8],
    ) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend { ... }
    fn write_all_buf<B: Buf + MaybeSend>(
        &mut self,
        buf: &mut B,
    ) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend { ... }
}
Expand description

An outgoing stream of bytes to the peer.

QUIC streams have flow control, which means the send rate is limited by the peer’s receive window. The stream is closed with a graceful FIN when dropped.

Required Associated Types§

Source

type Error: Error

Error type returned by send-side stream operations.

Required Methods§

Source

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

Write some of the buffer to the stream.

Implementations must not return Ok(0) when buf is non-empty.

Source

fn set_priority(&mut self, order: u8)

Set the stream’s priority.

Streams with lower values are sent first, but arrival order is not guaranteed.

Source

fn finish(&mut self) -> Result<(), Self::Error>

Mark the stream as finished, erroring on any future writes.

SendStream::reset can still be called to abandon queued data. SendStream::closed should return when the FIN is acknowledged by the peer.

NOTE: Quinn implicitly calls this on drop, but it is a common footgun. Implementations should call SendStream::reset on drop instead.

Source

fn reset(&mut self, code: u32)

Immediately close the stream and discard any remaining data.

This translates into a RESET_STREAM QUIC code. The peer may not receive the reset code if the stream is already closed.

Source

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

Block until the stream is closed by either side.

This includes:

Some implementations do not support FIN acknowledgement, in which case this blocks until the FIN is sent.

NOTE: This takes &mut to match Quinn and simplify the implementation.

Provided Methods§

Source

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

Write the given buffer to the stream, advancing the internal position.

Source

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

Write the entire Bytes chunk to the stream, potentially avoiding a copy.

Source

fn write_all( &mut self, buf: &[u8], ) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend

Helper to write all data in the buffer.

Source

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

Helper to write all data in the buffer.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§