Hi. I need a bit of a help comprehending the error here
fn read_to_start<'a, R: BufRead>(reader: &mut Reader<R>,buf: &'a mut Vec<u8>,) -> Option<BytesStart<'a>> {
match reader.read_event(buf).unwrap() {
Event::Start(ev) | Event::Empty(ev) => return Some(ev),
Event::Eof => return None,
_ => ()
}
read_to_start(reader, buf)
}
I get cannot borrow `*buf` as mutable more than once at a time
. Clearly it doesn't like the return Some(ev)
since replacing it with () makes error go away. But why does it not like it? Clearly in that branch where mutable borrow of buf
is retained - function terminates and the second mutable borrow is never reached, and in the branches where it is reached - the first reference isn't retained.
Originally this was the exact same code in a loop, but it also complained about buf
being borrowed as mutable in the previous iteration, so i tried to go for recursion to see if it also results in an error.
Am i missing something obvious here?