Struct nix_compat::wire::bytes::writer::BytesWriter
source · pub struct BytesWriter<W>where
W: AsyncWrite,{
inner: W,
payload_len: u64,
state: BytesPacketPosition,
}
Expand description
Writes a “bytes wire packet” to the underlying writer. The format is the same as in crate::wire::bytes::write_bytes, however this structure provides a AsyncWrite interface, allowing to not having to pass around the entire payload in memory.
It internally takes care of writing (non-payload) framing (size and padding).
During construction, the expected payload size needs to be provided.
After writing the payload to it, the user MUST call flush (or shutdown), which will validate the written payload size to match, and write the necessary padding.
In case flush is not called at the end, invalid data might be sent silently.
The underlying writer returning Ok(0)
is considered an EOF situation,
which is stronger than the “typically means the underlying object is no
longer able to accept bytes” interpretation from the docs. If such a
situation occurs, an error is returned.
The struct holds three fields, the underlying writer, the (expected) payload length, and an enum, tracking the state.
Fields§
§inner: W
§payload_len: u64
§state: BytesPacketPosition
Implementations§
source§impl<W> BytesWriter<W>where
W: AsyncWrite,
impl<W> BytesWriter<W>where
W: AsyncWrite,
Trait Implementations§
source§impl<W> AsyncWrite for BytesWriter<W>where
W: AsyncWrite,
impl<W> AsyncWrite for BytesWriter<W>where
W: AsyncWrite,
source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf
into the object. Read moresource§fn poll_flush(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
source§fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_shutdown( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
source§fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write
, except that it writes from a slice of buffers. Read moresource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read more