pub struct Writer(/* private fields */);
Expand description
Write half of a stream. See stream()
.
Implementations§
Source§impl Writer
impl Writer
Sourcepub fn write<F>(&self, size: usize, f: F) -> Result<()>
pub fn write<F>(&self, size: usize, f: F) -> Result<()>
Write data to this stream.
Space for size
bytes is allocated in the stream immediately, and then the callback is
invoked with a mutable slice to that region so that it may populate it. The slice given to
the callback may be larger than requested but will never be smaller.
The callback should return Ok
with the number of bytes actually written, which may be less
than size
. If the callback returns an error, that error is returned from write
as-is.
Note that we do not specially process Error::BufferTooSmall
as with Reader::read
.
Panics if the callback returns a number of bytes greater than the size of the buffer.
Sourcepub fn write_protocol_message<P: ProtocolMessage>(
&self,
message: &P,
) -> Result<()>
pub fn write_protocol_message<P: ProtocolMessage>( &self, message: &P, ) -> Result<()>
Write a protocol message to the stream. This is just a quick way to wire
ProtocolObject::write_bytes
in to write
.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Whether this stream is closed. Returns false so long as there is unread data in the buffer, even if the writer has hung up.
Sourcepub fn closed_reason(&self) -> Option<String>
pub fn closed_reason(&self) -> Option<String>
Get the reason this writer is closed. If the writer is not closed, or if
no reason was given, return None
.