Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation for core::io. #5673

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 68 additions & 8 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,89 @@ pub mod rustrt {

// FIXME (#2004): This is all buffered. We might need an unbuffered variant
// as well
/**
* The SeekStyle enum describes the relationship between the position
* we'd like to seek to from our current position. It's used as an argument
* to the `seek` method defined on the `Reader` trait.
*
* There are three seek styles:
*
* 1. `SeekSet` means that the new position should become our position.
* 2. `SeekCur` means that we should seek from the current position.
* 3. `SeekEnd` means that we should seek from the end.
*
* # Examples
*
* None right now.
*/
pub enum SeekStyle { SeekSet, SeekEnd, SeekCur, }


/// The raw underlying reader trait. All readers must implement this.
/**
* The core Reader trait. All readers must implement this trait.
*
* # Examples
*
* None right now.
*/
pub trait Reader {
// FIXME (#2004): Seekable really should be orthogonal.

/// Read up to len bytes (or EOF) and put them into bytes (which
/// must be at least len bytes long). Return number of bytes read.
// FIXME (#2982): This should probably return an error.
/**
* Reads bytes and puts them into `bytes`. 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.
*
* # Examples
*
* None right now.
*/
fn read(&self, bytes: &mut [u8], len: uint) -> uint;

/// Read a single byte, returning a negative value for EOF or read error.
/**
* Reads a single byte.
*
* In the case of an EOF or an error, returns a negative value.
*
* # Examples
*
* None right now.
*/
fn read_byte(&self) -> int;

/// Return whether the stream is currently at EOF position.
/**
* Returns a boolean value: are we currently at EOF?
*
* # Examples
*
* None right now.
*/
fn eof(&self) -> bool;

/// Move the current position within the stream. The second parameter
/// determines the position that the first parameter is relative to.
/**
* 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.
*
* # Examples
*
* None right now.
*/
fn seek(&self, position: int, style: SeekStyle);

/// Return the current position within the stream.
/**
* Returns the current position within the stream.
*
* # Examples
*
* None right now.
*/
fn tell(&self) -> uint;
}

Expand Down