Trait netio::Write
[−]
[src]
pub trait Write: Write { 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<()> { ... } fn by_ref(&mut self) -> &mut Self where Self: Sized { ... } fn retry(self) -> Retry<Self> where Self: Sized { ... } fn take(self, limit: u64) -> Take<Self> where Self: Sized { ... } }
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
by_ref
Methods that provide a slightly different functionality than their counterparts in
std::io::Write
:
write_all
New methods that have no counterpart in std::io::Write
:
retry
take
Functions that were removed or moved to a different trait, because they cannot be implemented with providing all desired guarantees:
write_fmt
Provided Methods
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this object, returning how many bytes were written.
This is just a "reexport" of std::io::Write::write
provided for convenience.
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
This is just a "reexport" of std::io::Write::flush
provided for convenience.
fn write_all<R: BufRead + ?Sized>(&mut self, buf: &mut R) -> Result<()>
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.
fn by_ref(&mut self) -> &mut Self where Self: Sized
Creates a "by reference" adaptor for this instance of Write
.
This is just a "reexport" of std::io::Write::by_ref
provided for convenience.
fn retry(self) -> Retry<Self> where Self: Sized
Transforms this writer into a writer that automatically retries on interrupts
The returned adapter will behave identically to the original writer,
except that it retries the writing operation automatically if an error of kind
ErrorKind::Interrupted
occurs.
Note
Methods that are already expected to retry are forwarded directly to the underlying writer.
fn take(self, limit: u64) -> Take<Self> where Self: Sized
Creates an adapter which will write at most limit
bytes to it.
This function returns a new instance of Write
which will write at most
limit
bytes, after which it will always return Ok(0).
Any write errors will not count towards the number of bytes written and future
calls to write
may succeed.
This function is equivalent to std::io::Read::take
but the returened adapter implements
Write
.
See also Read::take
.
Implementors
impl<W: Write> Write for W