std-method

BufRead::read_until: byte delimiter

Append bytes up to and including a delimiter, or until EOF. Unlike read_line, the content need not be valid UTF-8. Delimiter-free input can grow a vector without bounds. Expected stdout (not executed): 3 aa| Common mistake: Expecting the delimiter to be removed.

Formal Syntax & Structure

rust syntaxrust
reader.read_until(delimiter: u8, &mut Vec<u8>) -> io::Result<usize>

Working Example

Example Snippetrust
fn main() {    use std::io::BufRead;    let mut r = &b"aa|bb"[..];    let mut field = Vec::new();    let n = r.read_until(b'|', &mut field).unwrap();    println!("{n} {}", String::from_utf8(field).unwrap());}
Rust Reference