expression

Inspect and consume buffered bytes

Borrow the currently available buffered bytes without removing them. After the borrow ends, consume no more than the inspected available count. This supports incremental parsing without copying every field. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 2 cd Common mistake: Consuming more bytes than were available in the buffer.

Formal Syntax & Structure

rust syntaxrust
reader.fill_buf().await; reader.consume(n)

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    use tokio::io::{AsyncBufReadExt, BufReader};    let mut r = BufReader::with_capacity(2, &b"abcd"[..]);    let n = r.fill_buf().await.unwrap().len();    r.consume(n);    println!("{} {}", n, String::from_utf8_lossy(r.fill_buf().await.unwrap()));}
Rust Reference