Move state changing code into `fill_buf()` match because this code used only when one arm is matched
@@ -1128,8 +1128,7 @@ impl<'b, 'i, R: BufRead + 'i> BufferedInput<'b, 'i, &'b mut Vec<u8>> for R {
let start = buf.len();
while !done {
- let used = {
- let available = match self.fill_buf() {
+ let used = match self.fill_buf() {
Ok(n) if n.is_empty() => {
if read == 0 {
return Ok(None);
@@ -1137,14 +1136,7 @@ impl<'b, 'i, R: BufRead + 'i> BufferedInput<'b, 'i, &'b mut Vec<u8>> for R {
return Ok(Some(&buf[start..]));
}
}
- Ok(n) => n,
- Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue,
- Err(e) => {
- *position += read;
- return Err(Error::Io(e));
- }
- };
-
+ Ok(available) => {
if let Some((consumed, used)) = state.change(available) {
done = true;
buf.extend_from_slice(consumed);
@@ -1153,6 +1145,12 @@ impl<'b, 'i, R: BufRead + 'i> BufferedInput<'b, 'i, &'b mut Vec<u8>> for R {
buf.extend_from_slice(available);
available.len()
}
+ }
+ Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue,
+ Err(e) => {
+ *position += read;
+ return Err(Error::Io(e));
+ }
};
self.consume(used);
read += used;
