Trait Write
trait Write
A trait for objects which are byte-oriented sinks, modeled after its
std::io::Write counterpart.
The documentation for this trait is taken from the aforementioned std trait.
Required Methods
fn write(self: &mut Self, buf: &[u8]) -> Result<usize, Error>Write a buffer into this writer, returning how many bytes were written.
This function will attempt to write the entire contents of
buf, but the entire write might not succeed, or the write may also generate an error. A call towriterepresents at most one attempt to write to any wrapped object.Calls to
writeare not guaranteed to block waiting for data to be written, and a write which would otherwise block can be indicated through anErrvariant.If the return value is
Ok(n)then it must be guaranteed thatn <= buf.len(). A return value of0typically means that the underlying object is no longer able to accept bytes and will likely not be able to in the future as well, or that the buffer provided is empty.Errors
Each call to
writemay generate an I/O error indicating that the operation could not be completed. If an error is returned then no bytes in the buffer were written to this writer.It is not considered an error if the entire buffer could not be written to this writer.
An error of the
ErrorKind::Interruptedkind is non-fatal and the write operation should be retried if there is nothing else to do.fn flush(self: &mut Self) -> Result<(), Error>Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Errors
It is considered an error if not all bytes could be written due to I/O errors or EOF being reached.
Provided Methods
fn write_all(self: &mut Self, buf: &[u8]) -> Result<(), Error>Attempts to write an entire buffer into this writer.
This method will continuously call
writeuntil there is no more data to be written or an error of non-ErrorKind::Interruptedkind is returned. This method will not return until the entire buffer has been successfully written or such an error occurs. The first error that is not ofErrorKind::Interruptedkind generated from this method will be returned.If the buffer contains no data, this will never call
write.Errors
This function will return the first error of non-
ErrorKind::Interruptedkind thatwritereturns.fn by_ref(self: &mut Self) -> &mut Self where Self: SizedCreates a "by reference" adapter for this instance of
Write.The returned adapter also implements
Writeand will simply borrow this current writer.
Implementors
impl<W: Write> Write for GzipEncoder<W>impl Write for Vec<u8>impl Write for &mut [u8]impl<W: Write + ?Sized> Write for &mut Wimpl<W: Write> Write for ZlibEncoder<W>impl<W: Write> Write for DeflateEncoder<W>