trait
BufRead: buffered byte access
Buffered readers let callers inspect available bytes before marking them consumed. Higher-level helpers such as read_line use this interface. A buffer is not a guarantee of a complete record. Expected stdout (not executed): a ,b Common mistake: Consuming more bytes than were returned by fill_buf.
Formal Syntax & Structure
rust syntaxrust
trait BufRead: Read { fn fill_buf(&mut self) -> io::Result<&[u8]>; fn consume(&mut self, amount: usize); }Working Example
Example Snippetrust
fn main() { use std::io::BufRead; let mut reader = &b"a,b"[..]; let first = reader.fill_buf().unwrap()[0]; reader.consume(1); println!("{} {}", first as char, std::str::from_utf8(reader).unwrap());}