Trait zc_io::Write

source ·
pub trait Write {
    // Required methods
    fn write(&mut self, buf: &[u8]) -> Result<usize>;
    fn flush(&mut self) -> Result<()>;

    // Provided method
    fn write_all(&mut self, buf: &[u8]) -> Result<()> { ... }
}
Expand description

A simplified facade of io::Write for easier use in possibly no_std environments.

Required Methods§

source

fn write(&mut self, buf: &[u8]) -> Result<usize>

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 to write represents at most one attempt to write to any wrapped object.

Calls to write are not guaranteed to block waiting for data to be written, and a write which would otherwise block can be indicated through an Err variant.

If the return value is [Ok(n)] then it must be guaranteed that n <= buf.len(). A return value of 0 typically 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 write may 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::Interrupted kind is non-fatal and the write operation should be retried if there is nothing else to do.

source

fn flush(&mut self) -> Result<()>

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 getting reached.

Provided Methods§

source

fn write_all(&mut self, buf: &[u8]) -> Result<()>

Attempts to write an entire buffer into this writer.

This method will continuously call write until there is no more data to be written or an error of non-ErrorKind::Interrupted kind 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 of ErrorKind::Interrupted kind 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::Interrupted kind that write returns.

Implementations on Foreign Types§

source§

impl<W> Write for &mut Wwhere
W: ?Sized + Write,

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

fn write_all(&mut self, buf: &[u8]) -> Result<()>

source§

impl<W> Write for Box<W>where
W: ?Sized + Write,

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

fn write_all(&mut self, buf: &[u8]) -> Result<()>

source§

impl Write for &mut [u8]

Write is implemented for &mut [u8] by copying into the slice, overwriting its data.

Note that writing updates the slice to point to the yet unwritten part. The slice will be empty when it has been completely overwritten.

If the number of bytes to be written exceeds the size of the slice, write operations will return short writes: ultimately, Ok(0); in this situation, write_all returns an error of kind ErrorKind::WriteZero.

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

fn write_all(&mut self, buf: &[u8]) -> Result<()>

source§

impl Write for Vec<u8>

Write is implemented for Vec<u8> by appending to the vector. The vector will grow as needed.

source§

fn write(&mut self, data: &[u8]) -> Result<usize>

source§

fn flush(&mut self) -> Result<()>

source§

fn write_all(&mut self, data: &[u8]) -> Result<()>

Implementors§

source§

impl<W> Write for IoWriter<W>where
W: Write,

Available on crate feature std only.