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§
Required Methods§
Sourcefn write(
&mut self,
buf: &[u8],
) -> impl Future<Output = Result<usize, Self::Error>> + MaybeSend
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.
Sourcefn set_priority(&mut self, order: u8)
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.
Sourcefn finish(&mut self) -> Result<(), Self::Error>
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.
Sourcefn reset(&mut self, code: u32)
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.
Sourcefn closed(
&mut self,
) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend
fn closed( &mut self, ) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend
Block until the stream is closed by either side.
This includes:
- We sent a RESET_STREAM via SendStream::reset
- We received a STOP_SENDING via RecvStream::stop
- A FIN is acknowledged by the peer via SendStream::finish
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§
Sourcefn write_buf<B: Buf + MaybeSend>(
&mut self,
buf: &mut B,
) -> impl Future<Output = Result<usize, Self::Error>> + MaybeSend
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.
Sourcefn write_chunk(
&mut self,
chunk: Bytes,
) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".