Skip to main content

SendStream

Trait SendStream 

Source
pub trait SendStream: 'static {
    type Error: Error;
    type Group: SendGroup;
    type Offset: 'static;

Show 14 methods // Required methods fn offset(&self) -> Self::Offset; fn poll_write( &mut self, waiter: &Waiter, buf: &[u8], ) -> Poll<Result<usize, Self::Error>>; fn set_priority(&mut self, priority: i64); fn set_group(&mut self, group: &Self::Group); fn finish(&mut self) -> Result<(), Self::Error>; fn reset(&mut self, code: u32); fn reset_at(&mut self, offset: &Self::Offset, code: u32); fn poll_closed(&self, waiter: &Waiter) -> Poll<Result<(), Self::Error>>; // Provided methods fn poll_acked( &self, waiter: &Waiter, offset: &Self::Offset, ) -> Poll<Result<(), Self::Error>> { ... } fn poll_write_buf<B: Buf>( &mut self, waiter: &Waiter, buf: &mut B, ) -> Poll<Result<usize, Self::Error>> { ... } fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘ { ... } fn write_buf<'a, B: Buf>( &'a mut self, buf: &'a mut B, ) -> WriteBuf<'a, Self, B> ⓘ { ... } fn write_chunk(&mut self, chunk: Bytes) -> WriteChunk<'_, Self> ⓘ { ... } fn closed(&self) -> SendClosed<'_, Self> ⓘ { ... }
}
Expand description

An outgoing stream with partial writes, priorities, and reset codes.

Required Associated Types§

Source

type Error: Error

The error type for every operation on this stream.

Source

type Group: SendGroup

The transport’s send group, Ungrouped for a transport without them.

Source

type Offset: 'static

A position in the stream, minted only by offset, for poll_acked. () for a transport that cannot see acknowledgments.

Required Methods§

Source

fn offset(&self) -> Self::Offset

The position just past every byte written so far.

Source

fn poll_write( &mut self, waiter: &Waiter, buf: &[u8], ) -> Poll<Result<usize, Self::Error>>

Poll to write some of the buffer to the stream, returning how many bytes were written. See poll_write_buf for the partial-write contract, which this shares.

Source

fn set_priority(&mut self, priority: i64)

Set the priority within the stream’s send group, or session-wide when ungrouped.

Streams with higher values will be sent first, but are not guaranteed to arrive first. This matches the W3C WebTransport sendOrder convention.

Backends with a narrower priority saturate or approximate it, so treat the ordering as best-effort.

Source

fn set_group(&mut self, group: &Self::Group)

Move the stream into group, which belongs to this stream’s session.

Source

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

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

reset can still be called to abandon any queued data. poll_closed should resolve when the FIN is acknowledged by the peer.

Dropping an unfinished stream must reset it, so the peer cannot mistake truncated data for a complete stream.

Source

fn reset(&mut self, code: u32)

Immediately closes the stream and discards 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.

Takes &mut self rather than self even though it is terminal, so a caller can still poll_closed afterwards to await the peer, and so it matches finish, which must not consume the stream for exactly that reason.

Source

fn reset_at(&mut self, offset: &Self::Offset, code: u32)

Like reset, but still deliver every byte before offset.

The peer reads those bytes before the reset’s error only where the session’s reliable_reset says so; otherwise the transport may send a plain reset once it delivered them, which lets the peer discard any it has not read. A peer that stopped the stream gets the reset without them. Takes &mut self for the same reasons as reset.

Source

fn poll_closed(&self, waiter: &Waiter) -> Poll<Result<(), Self::Error>>

Poll until the stream is closed by either side.

This includes:

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

Provided Methods§

Source

fn poll_acked( &self, waiter: &Waiter, offset: &Self::Offset, ) -> Poll<Result<(), Self::Error>>

Poll until every byte below offset reaches the peer unless the session fails.

That is once the peer acknowledged them, or, over a reliable link such as qmux’s TCP, once the link took them, so a reset can no longer discard them. Errors once those bytes can never get there: the stream was reset by either side or the session closed. Bytes already acknowledged stay so after a reset or stop. The default, for a transport that cannot see acknowledgments, is ready at once: the bytes it took are all it knows. An offset minted by another stream may panic.

Source

fn poll_write_buf<B: Buf>( &mut self, waiter: &Waiter, buf: &mut B, ) -> Poll<Result<usize, Self::Error>>

Poll to write some of the given buffer to the stream, advancing it by the number of bytes written. This may be less than the whole buffer, so callers loop.

§Partial writes

Implementations must not advance buf past the bytes they accepted for sending. (Whether those bytes reach the peer is a separate matter: a reset or a dead connection can still discard accepted bytes.) A returned Poll::Pending must leave buf exactly where the accepted bytes end. Callers race writes against other work, so a byte taken from buf but never accepted becomes a silent hole in the stream, which the peer decodes as a truncated or garbage frame. Wait for send capacity before consuming from buf, never after.

Override this to avoid a copy when the underlying transport can take ownership of buf’s bytes: see Buf::copy_to_bytes, which is free for a Bytes source.

Source

fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘ

Write some of the buffer, returning how many bytes were accepted.

Source

fn write_buf<'a, B: Buf>(&'a mut self, buf: &'a mut B) -> WriteBuf<'a, Self, B> ⓘ

Write some of the buffer, advancing it by the bytes accepted.

Source

fn write_chunk(&mut self, chunk: Bytes) -> WriteChunk<'_, Self> ⓘ

Write the entire chunk to the stream.

Source

fn closed(&self) -> SendClosed<'_, Self> ⓘ

Wait until the stream is closed by either side.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§