@@ -2250,24 +2250,18 @@ fn skip_until<R: BufRead + ?Sized>(r: &mut R, delim: u8) -> Result<usize> {
2250
2250
/// ```
2251
2251
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2252
2252
pub trait BufRead : Read {
2253
- /// Returns the contents of the internal buffer, filling it with more data
2254
- /// from the inner reader if it is empty.
2253
+ /// Returns the contents of the internal buffer, filling it with more data, via Read methods, if empty.
2255
2254
///
2256
- /// This function is a lower-level call. It needs to be paired with the
2257
- /// [`consume`] method to function properly. When calling this
2258
- /// method, none of the contents will be "read" in the sense that later
2259
- /// calling `read` may return the same contents. As such, [`consume`] must
2260
- /// be called with the number of bytes that are consumed from this buffer to
2261
- /// ensure that the bytes are never returned twice.
2255
+ /// This is a lower-level method and is meant to be used together with [`consume`],
2256
+ /// which can be used to mark bytes that should not be returned by subsequent calls to `read`.
2262
2257
///
2263
2258
/// [`consume`]: BufRead::consume
2264
2259
///
2265
- /// An empty buffer returned indicates that the stream has reached EOF.
2260
+ /// Returns an empty buffer to indicate that the stream has reached EOF.
2266
2261
///
2267
2262
/// # Errors
2268
2263
///
2269
- /// This function will return an I/O error if the underlying reader was
2270
- /// read, but returned an error.
2264
+ /// Passes on I/O errors from Read.
2271
2265
///
2272
2266
/// # Examples
2273
2267
///
@@ -2285,26 +2279,20 @@ pub trait BufRead: Read {
2285
2279
/// // work with buffer
2286
2280
/// println!("{buffer:?}");
2287
2281
///
2288
- /// // ensure the bytes we worked with aren't returned again later
2289
- /// let length = buffer.len();
2290
- /// stdin.consume(length);
2282
+ /// // mark the bytes we worked with as read
2283
+ /// stdin.consume(buffer.len());
2291
2284
/// # std::io::Result::Ok(())
2292
2285
/// ```
2293
2286
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2294
2287
fn fill_buf ( & mut self ) -> Result < & [ u8 ] > ;
2295
2288
2296
- /// Tells this buffer that `amt` bytes have been consumed from the buffer,
2297
- /// so they should no longer be returned in calls to `read` .
2289
+ /// Marks the given `amount` of additional bytes from the internal buffer as having been read.
2290
+ /// Subsequent calls to `read` return bytes that have not yet been so marked .
2298
2291
///
2299
- /// This function is a lower-level call. It needs to be paired with the
2300
- /// [`fill_buf`] method to function properly. This function does
2301
- /// not perform any I/O, it simply informs this object that some amount of
2302
- /// its buffer, returned from [`fill_buf`], has been consumed and should
2303
- /// no longer be returned. As such, this function may do odd things if
2304
- /// [`fill_buf`] isn't called before calling it.
2292
+ /// This is a lower-level method and is meant to be used together with [`fill_buf`],
2293
+ /// which can be used to fill the internal buffer via Read methods.
2305
2294
///
2306
- /// The `amt` must be `<=` the number of bytes in the buffer returned by
2307
- /// [`fill_buf`].
2295
+ /// It is a logic error if `amount` exceeds the number of unread bytes in the internal buffer.
2308
2296
///
2309
2297
/// # Examples
2310
2298
///
@@ -2313,9 +2301,9 @@ pub trait BufRead: Read {
2313
2301
///
2314
2302
/// [`fill_buf`]: BufRead::fill_buf
2315
2303
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2316
- fn consume ( & mut self , amt : usize ) ;
2304
+ fn consume ( & mut self , amount : usize ) ;
2317
2305
2318
- /// Checks if the underlying `Read` has any data left to be read.
2306
+ /// Checks if there is any data left to be ` read` .
2319
2307
///
2320
2308
/// This function may fill the buffer to check for data,
2321
2309
/// so this functions returns `Result<bool>`, not `bool`.
@@ -2324,6 +2312,10 @@ pub trait BufRead: Read {
2324
2312
/// returned slice is empty (which means that there is no data left,
2325
2313
/// since EOF is reached).
2326
2314
///
2315
+ /// # Errors
2316
+ ///
2317
+ /// Passes on I/O errors from Read.
2318
+ ///
2327
2319
/// Examples
2328
2320
///
2329
2321
/// ```
0 commit comments