diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-08-20 00:45:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-20 00:45:54 -0400 |
| commit | 5fa33047a23934f638b635007616ad3a3170b9eb (patch) | |
| tree | a633ba0f176d1e14699d7c2457af4c32264bbbeb /library/std/src | |
| parent | 1e6df58e777f3504de7eeb94c5c2fd7f0387d181 (diff) | |
| parent | a7e8fe73111a96871feadda1eefa2b3f616cdb8e (diff) | |
| download | rust-5fa33047a23934f638b635007616ad3a3170b9eb.tar.gz rust-5fa33047a23934f638b635007616ad3a3170b9eb.zip | |
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.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/io/mod.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index d351ee5e739..ff0e29e04c2 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -2461,7 +2461,7 @@ pub trait BufRead: Read { /// delimiter or EOF is found. /// /// If successful, this function will return the total number of bytes read, - /// including the delimiter byte. + /// including the delimiter byte if found. /// /// This is useful for efficiently skipping data such as NUL-terminated strings /// in binary file formats without buffering. @@ -2489,7 +2489,7 @@ pub trait BufRead: Read { /// ``` /// use std::io::{self, BufRead}; /// - /// let mut cursor = io::Cursor::new(b"Ferris\0Likes long walks on the beach\0Crustacean\0"); + /// let mut cursor = io::Cursor::new(b"Ferris\0Likes long walks on the beach\0Crustacean\0!"); /// /// // read name /// let mut name = Vec::new(); @@ -2509,6 +2509,11 @@ pub trait BufRead: Read { /// .expect("reading from cursor won't fail"); /// assert_eq!(num_bytes, 11); /// assert_eq!(animal, b"Crustacean\0"); + /// + /// // reach EOF + /// let num_bytes = cursor.skip_until(b'\0') + /// .expect("reading from cursor won't fail"); + /// assert_eq!(num_bytes, 1); /// ``` #[stable(feature = "bufread_skip_until", since = "1.83.0")] fn skip_until(&mut self, byte: u8) -> Result<usize> { |
