Trait std::io::ReadExtUnstable
[-] [+]
[src]
pub trait ReadExt: Read + Sized { fn by_ref(&mut self) -> &mut Self { ... } fn bytes(self) -> Bytes<Self> { ... } fn chars(self) -> Chars<Self> { ... } fn chain<R: Read>(self, next: R) -> Chain<Self, R> { ... } fn take(self, limit: u64) -> Take<Self> { ... } fn tee<W: Write>(self, out: W) -> Tee<Self, W> { ... } }
Extension methods for all instances of Read
, typically imported through
std::io::prelude::*
.
Provided Methods
fn by_ref(&mut self) -> &mut Self
Create a "by reference" adaptor for this instance of Read
.
The returned adaptor also implements Read
and will simply borrow this
current reader.
fn bytes(self) -> Bytes<Self>
Transform this Read
instance to an Iterator
over its bytes.
The returned type implements Iterator
where the Item
is Result<u8,
R::Err>
. The yielded item is Ok
if a byte was successfully read and
Err
otherwise for I/O errors. EOF is mapped to returning None
from
this iterator.
fn chars(self) -> Chars<Self>
Transform this Read
instance to an Iterator
over char
s.
This adaptor will attempt to interpret this reader as an UTF-8 encoded
sequence of characters. The returned iterator will return None
once
EOF is reached for this reader. Otherwise each element yielded will be a
Result<char, E>
where E
may contain information about what I/O error
occurred or where decoding failed.
Currently this adaptor will discard intermediate data read, and should be avoided if this is not desired.
fn chain<R: Read>(self, next: R) -> Chain<Self, R>
Create an adaptor which will chain this stream with another.
The returned Read
instance will first read all bytes from this object
until EOF is encountered. Afterwards the output is equivalent to the
output of next
.
fn take(self, limit: u64) -> Take<Self>
Create an adaptor which will read at most limit
bytes from it.
This function returns a new instance of Read
which will read at most
limit
bytes, after which it will always return EOF (Ok(0)
). Any
read errors will not count towards the number of bytes read and future
calls to read
may succeed.
fn tee<W: Write>(self, out: W) -> Tee<Self, W>
Creates a reader adaptor which will write all read data into the given output stream.
Whenever the returned Read
instance is read it will write the read
data to out
. The current semantics of this implementation imply that
a write
error will not report how much data was initially read.