Skip to content

Commit 34c7b06

Browse files
authored
Unrolled build for #145006
Rollup merge of #145006 - ginnyTheCat:docs-skip-until, r=ibraheemdev Clarify EOF handling for `BufRead::skip_until` This aligns `BufRead::skip_until`'s description more with `BufRead::read_until` in terms of how it handles EOF and extends the doctest to include this behavior.
2 parents f605b57 + a7e8fe7 commit 34c7b06

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

library/std/src/io/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,7 @@ pub trait BufRead: Read {
24612461
/// delimiter or EOF is found.
24622462
///
24632463
/// If successful, this function will return the total number of bytes read,
2464-
/// including the delimiter byte.
2464+
/// including the delimiter byte if found.
24652465
///
24662466
/// This is useful for efficiently skipping data such as NUL-terminated strings
24672467
/// in binary file formats without buffering.
@@ -2489,7 +2489,7 @@ pub trait BufRead: Read {
24892489
/// ```
24902490
/// use std::io::{self, BufRead};
24912491
///
2492-
/// let mut cursor = io::Cursor::new(b"Ferris\0Likes long walks on the beach\0Crustacean\0");
2492+
/// let mut cursor = io::Cursor::new(b"Ferris\0Likes long walks on the beach\0Crustacean\0!");
24932493
///
24942494
/// // read name
24952495
/// let mut name = Vec::new();
@@ -2509,6 +2509,11 @@ pub trait BufRead: Read {
25092509
/// .expect("reading from cursor won't fail");
25102510
/// assert_eq!(num_bytes, 11);
25112511
/// assert_eq!(animal, b"Crustacean\0");
2512+
///
2513+
/// // reach EOF
2514+
/// let num_bytes = cursor.skip_until(b'\0')
2515+
/// .expect("reading from cursor won't fail");
2516+
/// assert_eq!(num_bytes, 1);
25122517
/// ```
25132518
#[stable(feature = "bufread_skip_until", since = "1.83.0")]
25142519
fn skip_until(&mut self, byte: u8) -> Result<usize> {

0 commit comments

Comments
 (0)