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: ?Sized>(&mut self, buf: &mut R) -> Result<()>
    where
        Self: Sized,
        R: BufRead
, { ... } }

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 → removed

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

  • Does not retry on ErrorKind::Interrupted.
  • Takes a BufRead instance instead of just a plain &[u8].

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.

Implementations on Foreign Types

impl Write for File
[src]

[src]

[src]

[src]

impl<'a> Write for &'a File
[src]

[src]

[src]

[src]

impl<W: Write> Write for BufWriter<W>
[src]

[src]

[src]

[src]

impl<W: Write> Write for LineWriter<W>
[src]

[src]

[src]

[src]

impl<'a> Write for Cursor<&'a mut [u8]>
[src]

[src]

[src]

[src]

impl Write for Cursor<Vec<u8>>
[src]

[src]

[src]

[src]

impl Write for Cursor<Box<[u8]>>
[src]

[src]

[src]

[src]

impl<'a> Write for &'a mut [u8]
[src]

[src]

[src]

[src]

impl Write for Vec<u8>
[src]

[src]

[src]

[src]

impl Write for Sink
[src]

[src]

[src]

[src]

impl Write for Stdout
[src]

[src]

[src]

[src]

impl<'a> Write for StdoutLock<'a>
[src]

[src]

[src]

[src]

impl Write for Stderr
[src]

[src]

[src]

[src]

impl<'a> Write for StderrLock<'a>
[src]

[src]

[src]

[src]

impl Write for TcpStream
[src]

[src]

[src]

[src]

impl<'a> Write for &'a TcpStream
[src]

[src]

[src]

[src]

impl Write for UnixStream
[src]

[src]

[src]

[src]

impl<'a> Write for &'a UnixStream
[src]

[src]

[src]

[src]

impl Write for ChildStdin
[src]

[src]

[src]

[src]

impl<'a, W: Write + ?Sized> Write for &'a mut W
[src]

[src]

[src]

[src]

impl<W: Write + ?Sized> Write for Box<W>
[src]

[src]

[src]

[src]

Implementors