read_while_any

Function read_while_any 

Source
pub fn read_while_any(
    reader: &mut impl BufRead,
    check_set: &[u8],
    to: &mut Vec<u8>,
) -> Result<(u8, usize)>
Expand description

Read from a BufRead stream while any of the specified bytes are found.

This function reads data from the stream while the current byte matches any byte in the provided check set. It stops when it encounters a byte not in the set.

§Arguments

  • reader - A BufRead stream to read from
  • check_set - A slice of bytes to match against
  • to - Buffer to store the read data

§Returns

Returns a tuple containing:

  • The first byte that didn’t match (the stop byte)
  • The number of bytes read

§Examples

use async_regex::read_while_any;
use std::io::Cursor;
 
let mut reader = Cursor::new(b"aaaaabbbccc");
let mut buffer = Vec::new();
let check_set = b"ab";
 
let (stop_byte, count) = read_while_any(&mut reader, check_set, &mut buffer).unwrap();
assert_eq!(buffer, b"aaaaabbb");
assert_eq!(stop_byte, b'c');