Skip to content

added docs +doctests to BufRead::consume #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/buf/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ impl<B: Buf + Sized> io::BufRead for Reader<B> {
fn fill_buf(&mut self) -> io::Result<&[u8]> {
Ok(self.buf.chunk())
}
/// consume `amt` bytes from the buffer.
///
/// Calls [`Buf::advance`] internally: If `amt` > `get_ref().remaining()` it
/// may **Panic** or advance to the end of the buf.
///
/// # Examples
/// ```rust
/// use bytes::Buf;
/// use std::io::{Read, BufRead};
///
/// let mut buf = b"hello world".reader();
/// let mut dst = vec![];
///
/// // skip b"hello "
/// buf.consume(6);
/// // read b"world"
/// buf.read_to_end(&mut dst).unwrap();
///
/// assert_eq!(dst, b"world");
/// ```
///
fn consume(&mut self, amt: usize) {
self.buf.advance(amt)
}
Expand Down