@@ -2251,24 +2251,18 @@ fn skip_until<R: BufRead + ?Sized>(r: &mut R, delim: u8) -> Result<usize> {
22512251#[ stable( feature = "rust1" , since = "1.0.0" ) ]
22522252#[ cfg_attr( not( test) , rustc_diagnostic_item = "IoBufRead" ) ]
22532253pub 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.
22562255 ///
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`.
22632258 ///
22642259 /// [`consume`]: BufRead::consume
22652260 ///
2266- /// An empty buffer returned indicates that the stream has reached EOF.
2261+ /// Returns an empty buffer when the stream has reached EOF.
22672262 ///
22682263 /// # Errors
22692264 ///
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.
22722266 ///
22732267 /// # Examples
22742268 ///
@@ -2286,26 +2280,21 @@ pub trait BufRead: Read {
22862280 /// // work with buffer
22872281 /// println!("{buffer:?}");
22882282 ///
2289- /// // ensure the bytes we worked with aren't returned again later
2283+ /// // mark the bytes we worked with as read
22902284 /// let length = buffer.len();
22912285 /// stdin.consume(length);
22922286 /// # std::io::Result::Ok(())
22932287 /// ```
22942288 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
22952289 fn fill_buf ( & mut self ) -> Result < & [ u8 ] > ;
22962290
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.
22992293 ///
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.
23062296 ///
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`].
23092298 ///
23102299 /// # Examples
23112300 ///
@@ -2314,9 +2303,9 @@ pub trait BufRead: Read {
23142303 ///
23152304 /// [`fill_buf`]: BufRead::fill_buf
23162305 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2317- fn consume ( & mut self , amt : usize ) ;
2306+ fn consume ( & mut self , amount : usize ) ;
23182307
2319- /// Checks if the underlying `Read` has any data left to be read.
2308+ /// Checks if there is any data left to be ` read` .
23202309 ///
23212310 /// This function may fill the buffer to check for data,
23222311 /// so this functions returns `Result<bool>`, not `bool`.
@@ -2325,6 +2314,10 @@ pub trait BufRead: Read {
23252314 /// returned slice is empty (which means that there is no data left,
23262315 /// since EOF is reached).
23272316 ///
2317+ /// # Errors
2318+ ///
2319+ /// This function will return an I/O error if a `Read` method was called, but returned an error.
2320+ ///
23282321 /// Examples
23292322 ///
23302323 /// ```
0 commit comments