I don't quite understand how the return makes the code not compile, it complains about a second mutable borrow but that borrow should never happen if the function returns.
use std::io::BufRead;
struct Foo<R: BufRead> {
r: R,
}
impl<R: BufRead> Foo<R> {
fn foo(&mut self) -> &[u8] {
let buf = self.r.fill_buf().unwrap();
if buf.len() > 1 {
// compiles if commented out
return buf;
}
drop(buf);
self.r.consume(1);
&[]
}
}
