Trait std::old_io::ReaderUnstable
[-] [+]
[src]
pub trait Reader { fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>; fn read_at_least(&mut self, min: usize, buf: &mut [u8]) -> IoResult<usize> { ... } fn read_byte(&mut self) -> IoResult<u8> { ... } fn push(&mut self, len: usize, buf: &mut Vec<u8>) -> IoResult<usize> { ... } fn push_at_least(&mut self, min: usize, len: usize, buf: &mut Vec<u8>) -> IoResult<usize> { ... } fn read_exact(&mut self, len: usize) -> IoResult<Vec<u8>> { ... } fn read_to_end(&mut self) -> IoResult<Vec<u8>> { ... } fn read_to_string(&mut self) -> IoResult<String> { ... } fn read_le_uint_n(&mut self, nbytes: usize) -> IoResult<u64> { ... } fn read_le_int_n(&mut self, nbytes: usize) -> IoResult<i64> { ... } fn read_be_uint_n(&mut self, nbytes: usize) -> IoResult<u64> { ... } fn read_be_int_n(&mut self, nbytes: usize) -> IoResult<i64> { ... } fn read_le_uint(&mut self) -> IoResult<usize> { ... } fn read_le_int(&mut self) -> IoResult<isize> { ... } fn read_be_uint(&mut self) -> IoResult<usize> { ... } fn read_be_int(&mut self) -> IoResult<isize> { ... } fn read_be_u64(&mut self) -> IoResult<u64> { ... } fn read_be_u32(&mut self) -> IoResult<u32> { ... } fn read_be_u16(&mut self) -> IoResult<u16> { ... } fn read_be_i64(&mut self) -> IoResult<i64> { ... } fn read_be_i32(&mut self) -> IoResult<i32> { ... } fn read_be_i16(&mut self) -> IoResult<i16> { ... } fn read_be_f64(&mut self) -> IoResult<f64> { ... } fn read_be_f32(&mut self) -> IoResult<f32> { ... } fn read_le_u64(&mut self) -> IoResult<u64> { ... } fn read_le_u32(&mut self) -> IoResult<u32> { ... } fn read_le_u16(&mut self) -> IoResult<u16> { ... } fn read_le_i64(&mut self) -> IoResult<i64> { ... } fn read_le_i32(&mut self) -> IoResult<i32> { ... } fn read_le_i16(&mut self) -> IoResult<i16> { ... } fn read_le_f64(&mut self) -> IoResult<f64> { ... } fn read_le_f32(&mut self) -> IoResult<f32> { ... } fn read_u8(&mut self) -> IoResult<u8> { ... } fn read_i8(&mut self) -> IoResult<i8> { ... } }
A trait for objects which are byte-oriented streams. Readers are defined by
one method, read
. This function will block until data is available,
filling in the provided buffer with any data read.
Readers are intended to be composable with one another. Many objects
throughout the I/O and related libraries take and provide types which
implement the Reader
trait.
Required Methods
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
Read bytes, up to the length of buf
and place them in buf
.
Returns the number of bytes read. The number of bytes read may
be less than the number requested, even 0. Returns Err
on EOF.
Error
If an error occurs during this I/O operation, then it is returned as
Err(IoError)
. Note that end-of-file is considered an error, and can be
inspected for in the error's kind
field. Also note that reading 0
bytes is not considered an error in all circumstances
Implementation Note
When implementing this method on a new Reader, you are strongly encouraged not to return 0 if you can avoid it.
Provided Methods
fn read_at_least(&mut self, min: usize, buf: &mut [u8]) -> IoResult<usize>
Reads at least min
bytes and places them in buf
.
Returns the number of bytes read.
This will continue to call read
until at least min
bytes have been
read. If read
returns 0 too many times, NoProgress
will be
returned.
Error
If an error occurs at any point, that error is returned, and no further bytes are read.
fn read_byte(&mut self) -> IoResult<u8>
Reads a single byte. Returns Err
on EOF.
fn push(&mut self, len: usize, buf: &mut Vec<u8>) -> IoResult<usize>
Reads up to len
bytes and appends them to a vector.
Returns the number of bytes read. The number of bytes read may be
less than the number requested, even 0. Returns Err on EOF.
Error
If an error occurs during this I/O operation, then it is returned
as Err(IoError)
. See read()
for more details.
fn push_at_least(&mut self, min: usize, len: usize, buf: &mut Vec<u8>) -> IoResult<usize>
Reads at least min
bytes, but no more than len
, and appends them to
a vector.
Returns the number of bytes read.
This will continue to call read
until at least min
bytes have been
read. If read
returns 0 too many times, NoProgress
will be
returned.
Error
If an error occurs at any point, that error is returned, and no further bytes are read.
fn read_exact(&mut self, len: usize) -> IoResult<Vec<u8>>
Reads exactly len
bytes and gives you back a new vector of length
len
Error
Fails with the same conditions as read
. Additionally returns error
on EOF. Note that if an error is returned, then some number of bytes may
have already been consumed from the underlying reader, and they are lost
(not returned as part of the error). If this is unacceptable, then it is
recommended to use the push_at_least
or read
methods.
fn read_to_end(&mut self) -> IoResult<Vec<u8>>
Reads all remaining bytes from the stream.
Error
Returns any non-EOF error immediately. Previously read bytes are discarded when an error is returned.
When EOF is encountered, all bytes read up to that point are returned.
fn read_to_string(&mut self) -> IoResult<String>
Reads all of the remaining bytes of this stream, interpreting them as a UTF-8 encoded stream. The corresponding string is returned.
Error
This function returns all of the same errors as read_to_end
with an
additional error if the reader's contents are not a valid sequence of
UTF-8 bytes.
fn read_le_uint_n(&mut self, nbytes: usize) -> IoResult<u64>
Reads n
little-endian unsigned integer bytes.
n
must be between 1 and 8, inclusive.
fn read_le_int_n(&mut self, nbytes: usize) -> IoResult<i64>
Reads n
little-endian signed integer bytes.
n
must be between 1 and 8, inclusive.
fn read_be_uint_n(&mut self, nbytes: usize) -> IoResult<u64>
Reads n
big-endian unsigned integer bytes.
n
must be between 1 and 8, inclusive.
fn read_be_int_n(&mut self, nbytes: usize) -> IoResult<i64>
Reads n
big-endian signed integer bytes.
n
must be between 1 and 8, inclusive.
fn read_le_uint(&mut self) -> IoResult<usize>
Reads a little-endian unsigned integer.
The number of bytes returned is system-dependent.
fn read_le_int(&mut self) -> IoResult<isize>
Reads a little-endian integer.
The number of bytes returned is system-dependent.
fn read_be_uint(&mut self) -> IoResult<usize>
Reads a big-endian unsigned integer.
The number of bytes returned is system-dependent.
fn read_be_int(&mut self) -> IoResult<isize>
Reads a big-endian integer.
The number of bytes returned is system-dependent.
fn read_be_u64(&mut self) -> IoResult<u64>
Reads a big-endian u64
.
u64
s are 8 bytes long.
fn read_be_u32(&mut self) -> IoResult<u32>
Reads a big-endian u32
.
u32
s are 4 bytes long.
fn read_be_u16(&mut self) -> IoResult<u16>
Reads a big-endian u16
.
u16
s are 2 bytes long.
fn read_be_i64(&mut self) -> IoResult<i64>
Reads a big-endian i64
.
i64
s are 8 bytes long.
fn read_be_i32(&mut self) -> IoResult<i32>
Reads a big-endian i32
.
i32
s are 4 bytes long.
fn read_be_i16(&mut self) -> IoResult<i16>
Reads a big-endian i16
.
i16
s are 2 bytes long.
fn read_be_f64(&mut self) -> IoResult<f64>
Reads a big-endian f64
.
f64
s are 8 byte, IEEE754 double-precision floating point numbers.
fn read_be_f32(&mut self) -> IoResult<f32>
Reads a big-endian f32
.
f32
s are 4 byte, IEEE754 single-precision floating point numbers.
fn read_le_u64(&mut self) -> IoResult<u64>
Reads a little-endian u64
.
u64
s are 8 bytes long.
fn read_le_u32(&mut self) -> IoResult<u32>
Reads a little-endian u32
.
u32
s are 4 bytes long.
fn read_le_u16(&mut self) -> IoResult<u16>
Reads a little-endian u16
.
u16
s are 2 bytes long.
fn read_le_i64(&mut self) -> IoResult<i64>
Reads a little-endian i64
.
i64
s are 8 bytes long.
fn read_le_i32(&mut self) -> IoResult<i32>
Reads a little-endian i32
.
i32
s are 4 bytes long.
fn read_le_i16(&mut self) -> IoResult<i16>
Reads a little-endian i16
.
i16
s are 2 bytes long.
fn read_le_f64(&mut self) -> IoResult<f64>
Reads a little-endian f64
.
f64
s are 8 byte, IEEE754 double-precision floating point numbers.
fn read_le_f32(&mut self) -> IoResult<f32>
Reads a little-endian f32
.
f32
s are 4 byte, IEEE754 single-precision floating point numbers.
fn read_u8(&mut self) -> IoResult<u8>
Read a u8.
u8
s are 1 byte.
fn read_i8(&mut self) -> IoResult<i8>
Read an i8.
i8
s are 1 byte.
Implementors
impl<R: Reader> Reader for BufferedReader<R>
impl<S: Stream> Reader for BufferedStream<S>
impl Reader for ChanReader
impl Reader for MemReader
impl<'a> Reader for &'a [u8]
impl<'a> Reader for BufReader<'a>
impl<R: Reader> Reader for IoResult<R>
impl Reader for File
impl Reader for TcpStream
impl Reader for UnixStream
impl Reader for PipeStream
impl Reader for StdinReader
impl Reader for StdReader
impl<R: Reader> Reader for LimitReader<R>
impl Reader for ZeroReader
impl Reader for NullReader
impl<R: Reader, I: Iterator<Item=R>> Reader for ChainedReader<I, R>
impl<R: Reader, W: Writer> Reader for TeeReader<R, W>
impl<T: Iterator<Item=u8>> Reader for IterReader<T>
impl<'a> Reader for Box<Reader + 'a>
impl<'a> Reader for &'a mut Reader + 'a
impl<'a, R: Reader> Reader for RefReader<'a, R>