Trait std::io::Reader

pub trait Reader {
    fn read(&self, bytes: &mut [u8], len: uint) -> uint;
    fn read_byte(&self) -> int;
    fn eof(&self) -> bool;
    fn seek(&self, position: int, style: SeekStyle);
    fn tell(&self) -> uint;
}

The core Reader trait. All readers must implement this trait.

Examples

None right now.

Required Methods

fn read(&self, bytes: &mut [u8], len: uint) -> uint

Reads bytes and puts them into bytes, advancing the cursor. Returns the number of bytes read.

The number of bytes to be read is len or the end of the file, whichever comes first.

The buffer must be at least len bytes long.

read is conceptually similar to C's fread function.

Examples

None right now.

fn read_byte(&self) -> int

Reads a single byte, advancing the cursor.

In the case of an EOF or an error, returns a negative value.

read_byte is conceptually similar to C's getc function.

Examples

None right now.

fn eof(&self) -> bool

Returns a boolean value: are we currently at EOF?

Note that stream position may be already at the end-of-file point, but eof returns false until an attempt to read at that position.

eof is conceptually similar to C's feof function.

Examples

None right now.

fn seek(&self, position: int, style: SeekStyle)

Seek to a given position in the stream.

Takes an optional SeekStyle, which affects how we seek from the position. See SeekStyle docs for more details.

seek is conceptually similar to C's fseek function.

Examples

None right now.

fn tell(&self) -> uint

Returns the current position within the stream.

tell is conceptually similar to C's ftell function.

Examples

None right now.

Implementors