Trait netio::Write [] [src]

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

    fn write_all<R: BufRead + ?Sized>(&mut self, buf: &mut R) -> Result<()> { ... }
}

Alternative to std::io::Write

This trait is automatically implemented for all types that implement std::io::Write.

Differences to std::io::Write

Methods that are just wrappers around the equivalent methods of std::io::Write:

  • write
  • flush

Methods that provide a slightly different functionality than their counterparts in std::io::Write:

  • write_all

Functions that were removed or moved to a different trait, because they cannot be implemented with providing all desired guarantees:

  • write_fmt

Required Methods

Write a buffer into this object, returning how many bytes were written.

This method is equivalent to std::io::Write::write.

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.

This method is equivalent to std::io::Write::flush.

Provided Methods

Attempts to write an entire buffer into this write.

Similarly to std::io::Write::write_all, this method will continuously call write while there is more data to write. This method will not return until the entire buffer has been successfully written or an error occurs. The first error generated from this method will be returned.

The supplied buffer will be consumed by the writing operation.

Errors

This function will return an error immediately if any call to write returns any kind of error. Instances of ErrorKind::Interrupted are not handled by this function.

All bytes consumed from the buffer will be written to the the writer and vice versa. It is guaranteed that no data is lost in case of error.

Differences to std::io::Write::write_all

Advantages

  • Function is interruptable, e.g. to allow graceful shutdown for server applications.
  • In case of error, it is always clear how much data was already written. No data is lost.

Implementors