From 14bec099521d4c26eb05a574900454f3c4960344 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 22 Dec 2015 15:36:25 -0700 Subject: [PATCH] Clean up read_all --- src/util.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/util.rs b/src/util.rs index 662eb7c8..97a992eb 100644 --- a/src/util.rs +++ b/src/util.rs @@ -6,11 +6,10 @@ pub fn parse_update_count(tag: String) -> u64 { } pub fn read_all(r: &mut R, mut buf: &mut [u8]) -> io::Result<()> { - let mut start = 0; - while start != buf.len() { - match r.read(&mut buf[start..]) { + while !buf.is_empty() { + match r.read(buf) { Ok(0) => return Err(io::Error::new(io::ErrorKind::Other, "unexpected EOF")), - Ok(len) => start += len, + Ok(len) => buf = &mut {buf}[len..], Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {} Err(e) => return Err(e), }