pub struct SendStream { /* private fields */ }
Expand description
A stream that can only be used to send data.
If dropped, streams that haven’t been explicitly reset()
will be
implicitly finish()
ed, continuing to (re)transmit previously written
data until it has been fully acknowledged or the connection is closed.
§Cancellation
A write
method is said to be cancel-safe when dropping its future before
the future becomes ready will always result in no data being written to the
stream. This is true of methods which succeed immediately when any progress
is made, and is not true of methods which might need to perform multiple
writes internally before succeeding. Each write
method documents whether
it is cancel-safe.
Implementations§
Source§impl SendStream
impl SendStream
Sourcepub fn finish(&mut self) -> Result<(), ClosedStream>
pub fn finish(&mut self) -> Result<(), ClosedStream>
Notify the peer that no more data will ever be written to this stream.
It is an error to write to a stream after finish()
ing it. reset()
may still be called after finish
to abandon transmission of any stream
data that might still be buffered.
To wait for the peer to receive all buffered stream data, see
stopped()
.
May fail if finish()
or reset()
was previously called.This
error is harmless and serves only to indicate that the caller may have
incorrect assumptions about the stream’s state.
Sourcepub fn reset(&mut self, error_code: VarInt) -> Result<(), ClosedStream>
pub fn reset(&mut self, error_code: VarInt) -> Result<(), ClosedStream>
Close the stream immediately.
No new data can be written after calling this method. Locally buffered data is dropped, and previously transmitted data will no longer be retransmitted if lost. If an attempt has already been made to finish the stream, the peer may still receive all written data.
May fail if finish()
or reset()
was
previously called. This error is harmless and serves only to
indicate that the caller may have incorrect assumptions about the
stream’s state.
Sourcepub fn set_priority(&self, priority: i32) -> Result<(), ClosedStream>
pub fn set_priority(&self, priority: i32) -> Result<(), ClosedStream>
Set the priority of the stream.
Every stream has an initial priority of 0. Locally buffered data from streams with higher priority will be transmitted before data from streams with lower priority. Changing the priority of a stream with pending data may only take effect after that data has been transmitted. Using many different priority levels per connection may have a negative impact on performance.
Sourcepub fn priority(&self) -> Result<i32, ClosedStream>
pub fn priority(&self) -> Result<i32, ClosedStream>
Get the priority of the stream
Sourcepub async fn stopped(&mut self) -> Result<Option<VarInt>, StoppedError>
pub async fn stopped(&mut self) -> Result<Option<VarInt>, StoppedError>
Completes when the peer stops the stream or reads the stream to completion.
Yields Some
with the stop error code if the peer stops the stream.
Yields None
if the local side finish()
es the stream
and then the peer acknowledges receipt of all stream data (although not
necessarily the processing of it), after which the peer closing the
stream is no longer meaningful.
For a variety of reasons, the peer may not send acknowledgements
immediately upon receiving data. As such, relying on stopped
to
know when the peer has read a stream to completion may introduce
more latency than using an application-level response of some sort.
Sourcepub async fn write(&mut self, buf: &[u8]) -> Result<usize, WriteError>
pub async fn write(&mut self, buf: &[u8]) -> Result<usize, WriteError>
Write bytes to the stream.
Yields the number of bytes written on success. Congestion and flow
control may cause this to be shorter than buf.len()
, indicating
that only a prefix of buf
was written.
This operation is cancel-safe.
Sourcepub async fn write_all(&mut self, buf: &[u8]) -> Result<(), WriteError>
pub async fn write_all(&mut self, buf: &[u8]) -> Result<(), WriteError>
Convenience method to write an entire buffer to the stream.
This operation is not cancel-safe.
Sourcepub async fn write_chunks(
&mut self,
bufs: &mut [Bytes],
) -> Result<Written, WriteError>
pub async fn write_chunks( &mut self, bufs: &mut [Bytes], ) -> Result<Written, WriteError>
Write chunks to the stream.
Yields the number of bytes and chunks written on success.
Congestion and flow control may cause this to be shorter than
buf.len()
, indicating that only a prefix of bufs
was written.
This operation is cancel-safe.
Sourcepub async fn write_all_chunks(
&mut self,
bufs: &mut [Bytes],
) -> Result<(), WriteError>
pub async fn write_all_chunks( &mut self, bufs: &mut [Bytes], ) -> Result<(), WriteError>
Convenience method to write an entire list of chunks to the stream.
This operation is not cancel-safe.
Trait Implementations§
Source§impl AsyncWrite for SendStream
impl AsyncWrite for SendStream
Source§async fn flush(&mut self) -> Result<()>
async fn flush(&mut self) -> Result<()>
Source§async fn shutdown(&mut self) -> Result<()>
async fn shutdown(&mut self) -> Result<()>
Source§async fn write_vectored<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoVectoredBuf,
async fn write_vectored<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoVectoredBuf,
write
, except that it write bytes from a buffer implements
IoVectoredBuf
into the source. Read moreSource§impl AsyncWrite for SendStream
Available on crate feature io-compat
only.
impl AsyncWrite for SendStream
io-compat
only.Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf
into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
Source§impl Debug for SendStream
impl Debug for SendStream
Auto Trait Implementations§
impl Freeze for SendStream
impl RefUnwindSafe for SendStream
impl Send for SendStream
impl Sync for SendStream
impl Unpin for SendStream
impl UnwindSafe for SendStream
Blanket Implementations§
Source§impl<A> AsyncWriteExt for Awhere
A: AsyncWrite + ?Sized,
impl<A> AsyncWriteExt for Awhere
A: AsyncWrite + ?Sized,
Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
AsyncWrite
. Read moreSource§async fn write_all<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoBuf,
async fn write_all<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoBuf,
Source§async fn write_vectored_all<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoVectoredBuf,
async fn write_vectored_all<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoVectoredBuf,
AsyncWrite::write_vectored
, except that it tries to write the entire
contents of the buffer into this writer.Source§async fn write_u8(&mut self, num: u8) -> Result<(), Error>
async fn write_u8(&mut self, num: u8) -> Result<(), Error>
u8
into the underlying writer.Source§async fn write_u8_le(&mut self, num: u8) -> Result<(), Error>
async fn write_u8_le(&mut self, num: u8) -> Result<(), Error>
u8
into the underlying writer.Source§async fn write_u16(&mut self, num: u16) -> Result<(), Error>
async fn write_u16(&mut self, num: u16) -> Result<(), Error>
u16
into the underlying writer.Source§async fn write_u16_le(&mut self, num: u16) -> Result<(), Error>
async fn write_u16_le(&mut self, num: u16) -> Result<(), Error>
u16
into the underlying writer.Source§async fn write_u32(&mut self, num: u32) -> Result<(), Error>
async fn write_u32(&mut self, num: u32) -> Result<(), Error>
u32
into the underlying writer.Source§async fn write_u32_le(&mut self, num: u32) -> Result<(), Error>
async fn write_u32_le(&mut self, num: u32) -> Result<(), Error>
u32
into the underlying writer.Source§async fn write_u64(&mut self, num: u64) -> Result<(), Error>
async fn write_u64(&mut self, num: u64) -> Result<(), Error>
u64
into the underlying writer.Source§async fn write_u64_le(&mut self, num: u64) -> Result<(), Error>
async fn write_u64_le(&mut self, num: u64) -> Result<(), Error>
u64
into the underlying writer.Source§async fn write_u128(&mut self, num: u128) -> Result<(), Error>
async fn write_u128(&mut self, num: u128) -> Result<(), Error>
u128
into the underlying writer.Source§async fn write_u128_le(&mut self, num: u128) -> Result<(), Error>
async fn write_u128_le(&mut self, num: u128) -> Result<(), Error>
u128
into the underlying writer.Source§async fn write_i8(&mut self, num: i8) -> Result<(), Error>
async fn write_i8(&mut self, num: i8) -> Result<(), Error>
i8
into the underlying writer.Source§async fn write_i8_le(&mut self, num: i8) -> Result<(), Error>
async fn write_i8_le(&mut self, num: i8) -> Result<(), Error>
i8
into the underlying writer.Source§async fn write_i16(&mut self, num: i16) -> Result<(), Error>
async fn write_i16(&mut self, num: i16) -> Result<(), Error>
i16
into the underlying writer.Source§async fn write_i16_le(&mut self, num: i16) -> Result<(), Error>
async fn write_i16_le(&mut self, num: i16) -> Result<(), Error>
i16
into the underlying writer.Source§async fn write_i32(&mut self, num: i32) -> Result<(), Error>
async fn write_i32(&mut self, num: i32) -> Result<(), Error>
i32
into the underlying writer.Source§async fn write_i32_le(&mut self, num: i32) -> Result<(), Error>
async fn write_i32_le(&mut self, num: i32) -> Result<(), Error>
i32
into the underlying writer.Source§async fn write_i64(&mut self, num: i64) -> Result<(), Error>
async fn write_i64(&mut self, num: i64) -> Result<(), Error>
i64
into the underlying writer.Source§async fn write_i64_le(&mut self, num: i64) -> Result<(), Error>
async fn write_i64_le(&mut self, num: i64) -> Result<(), Error>
i64
into the underlying writer.Source§async fn write_i128(&mut self, num: i128) -> Result<(), Error>
async fn write_i128(&mut self, num: i128) -> Result<(), Error>
i128
into the underlying writer.Source§async fn write_i128_le(&mut self, num: i128) -> Result<(), Error>
async fn write_i128_le(&mut self, num: i128) -> Result<(), Error>
i128
into the underlying writer.Source§async fn write_f32(&mut self, num: f32) -> Result<(), Error>
async fn write_f32(&mut self, num: f32) -> Result<(), Error>
f32
into the underlying writer.Source§async fn write_f32_le(&mut self, num: f32) -> Result<(), Error>
async fn write_f32_le(&mut self, num: f32) -> Result<(), Error>
f32
into the underlying writer.Source§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
Source§fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
AsyncWrite
. Read moreSource§fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
AsyncWrite
.Source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
buf
into the object. Read moreSource§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
bufs
into the object using vectored
IO operations. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more