Skip to content

Commit feefadd

Browse files
committed
added docs +doctests to BufRead::Consume
1 parent 141cbc2 commit feefadd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/buf/reader.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ impl<B: Buf + Sized> io::BufRead for Reader<B> {
7575
fn fill_buf(&mut self) -> io::Result<&[u8]> {
7676
Ok(self.buf.chunk())
7777
}
78+
/// consume `amt` bytes from the buffer.
79+
///
80+
/// Calls [`Buf::advance`] internally and will therefore not lead to a logic error.
81+
///
82+
/// # Examples
83+
/// ```rust
84+
/// use bytes::Buf;
85+
/// use std::io::{Read, BufRead};
86+
///
87+
/// let mut buf = b"hello world".reader();
88+
/// let mut dst = vec![];
89+
///
90+
/// // skip b"hello "
91+
/// buf.consume(6);
92+
/// // read b"world"
93+
/// buf.read_to_end(&mut dst).unwrap();
94+
///
95+
/// assert_eq!(dst, b"world");
96+
/// ```
97+
///
7898
fn consume(&mut self, amt: usize) {
7999
self.buf.advance(amt)
80100
}

0 commit comments

Comments
 (0)