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