Skip to content

Commit 1065a92

Browse files
committed
Elaborate a bit in the Reader docs regarding stream position.
Had a conversation with @cmr in IRC about some places that these docs were confusing. The functions that advance the stream now say so. In addition, I think that calling out the similarities to familliar C functions should help people coming from other languages.
1 parent 9f67169 commit 1065a92

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/libcore/io.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,29 @@ pub trait Reader {
8484

8585
// FIXME (#2982): This should probably return an error.
8686
/**
87-
* Reads bytes and puts them into `bytes`. Returns the number of
88-
* bytes read.
87+
* Reads bytes and puts them into `bytes`, advancing the cursor. Returns the
88+
* number of bytes read.
8989
*
9090
* The number of bytes to be read is `len` or the end of the file,
9191
* whichever comes first.
9292
*
9393
* The buffer must be at least `len` bytes long.
9494
*
95+
* `read` is conceptually similar to C's `fread`.
96+
*
9597
* # Examples
9698
*
9799
* None right now.
98100
*/
99101
fn read(&self, bytes: &mut [u8], len: uint) -> uint;
100102

101103
/**
102-
* Reads a single byte.
104+
* Reads a single byte, advancing the cursor.
103105
*
104106
* In the case of an EOF or an error, returns a negative value.
105107
*
108+
* `read_byte` is conceptually similar to C's `getc` function.
109+
*
106110
* # Examples
107111
*
108112
* None right now.
@@ -112,6 +116,8 @@ pub trait Reader {
112116
/**
113117
* Returns a boolean value: are we currently at EOF?
114118
*
119+
* `eof` is conceptually similar to C's `feof` function.
120+
*
115121
* # Examples
116122
*
117123
* None right now.
@@ -124,6 +130,8 @@ pub trait Reader {
124130
* Takes an optional SeekStyle, which affects how we seek from the
125131
* position. See `SeekStyle` docs for more details.
126132
*
133+
* `seek` is conceptually similar to C's `fseek`.
134+
*
127135
* # Examples
128136
*
129137
* None right now.
@@ -133,6 +141,8 @@ pub trait Reader {
133141
/**
134142
* Returns the current position within the stream.
135143
*
144+
* `tell` is conceptually similar to C's `ftell` function.
145+
*
136146
* # Examples
137147
*
138148
* None right now.

0 commit comments

Comments
 (0)