Function fill_buf_until_match

Source
pub fn fill_buf_until_match<I, T>(
    it: &mut I,
    buf: &mut Vec<T>,
    want: T,
) -> Result<()>
where I: Iterator<Item = Result<T>>, T: PartialEq,
Expand description

fill the buffer from it until and including the first item that matches want

let mut it = vec![1, 1, 2].into_iter().map(|t| Ok(t));
let mut buf: Vec<u8> = vec![3];
fill_buf_until_match(&mut it, &mut buf, 3).unwrap();
assert_eq!(vec![3, 1, 1, 2], buf);