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
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this object, returning how many bytes were written.
This method is equivalent to std::io::Write::write
.
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
This method is equivalent to std::io::Write::flush
.
Provided Methods
fn write_all<R: ?Sized>(&mut self, buf: &mut R) -> Result<()> where
Self: Sized,
R: BufRead,
Self: Sized,
R: BufRead,
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.
Implementors
impl Write for File
impl<'a> Write for &'a File
impl<W: Write> Write for BufWriter<W>
impl<W: Write> Write for LineWriter<W>
impl<'a> Write for Cursor<&'a mut [u8]>
impl Write for Cursor<Vec<u8>>
impl Write for Cursor<Box<[u8]>>
impl<'a> Write for &'a mut [u8]
impl Write for Vec<u8>
impl Write for Sink
impl Write for Stdout
impl<'a> Write for StdoutLock<'a>
impl Write for Stderr
impl<'a> Write for StderrLock<'a>
impl Write for TcpStream
impl<'a> Write for &'a TcpStream
impl Write for UnixStream
impl<'a> Write for &'a UnixStream
impl Write for ChildStdin
impl<'a, W: Write + ?Sized> Write for &'a mut W
impl<W: Write + ?Sized> Write for Box<W>
impl<I: Write> Write for Retry<I>
impl<T: Write> Write for Take<T>
impl<R: Write> Write for Compat<R>
impl<T: Write> Write for Limited<T>