Skip to content

Commit 16bc4b9

Browse files
committed
Use Read::read_exact
1 parent 86a9eb8 commit 16bc4b9

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

src/message.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::time::Duration;
55
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
66

77
use types::Oid;
8-
use util;
98
use priv_io::StreamOptions;
109

1110
use self::BackendMessage::*;
@@ -438,7 +437,7 @@ fn read_data_row<R: BufRead>(buf: &mut R) -> io::Result<BackendMessage> {
438437
-1 => None,
439438
len => {
440439
let mut data = vec![0; len as usize];
441-
try!(util::read_all(buf, &mut data));
440+
try!(buf.read_exact(&mut data));
442441
Some(data)
443442
}
444443
};
@@ -455,7 +454,7 @@ fn read_auth_message<R: Read>(buf: &mut R) -> io::Result<BackendMessage> {
455454
3 => AuthenticationCleartextPassword,
456455
5 => {
457456
let mut salt = [0; 4];
458-
try!(util::read_all(buf, &mut salt));
457+
try!(buf.read_exact(&mut salt));
459458
AuthenticationMD5Password { salt: salt }
460459
}
461460
6 => AuthenticationSCMCredential,

src/types/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub use self::slice::Slice;
1111
pub use self::types::Type;
1212
use {Result, SessionInfoNew, InnerConnection, OtherNew, WrongTypeNew, FieldNew};
1313
use error::Error;
14-
use util;
1514

1615
/// Generates a simple implementation of `ToSql::accepts` which accepts the
1716
/// types passed to it.
@@ -409,7 +408,7 @@ impl FromSql for HashMap<String, Option<String>> {
409408
for _ in 0..count {
410409
let key_len = try!(raw.read_i32::<BigEndian>());
411410
let mut key = vec![0; key_len as usize];
412-
try!(util::read_all(raw, &mut key));
411+
try!(raw.read_exact(&mut key));
413412
let key = match String::from_utf8(key) {
414413
Ok(key) => key,
415414
Err(err) => return Err(Error::Conversion(Box::new(err))),
@@ -420,7 +419,7 @@ impl FromSql for HashMap<String, Option<String>> {
420419
None
421420
} else {
422421
let mut val = vec![0; val_len as usize];
423-
try!(util::read_all(raw, &mut val));
422+
try!(raw.read_exact(&mut val));
424423
match String::from_utf8(val) {
425424
Ok(val) => Some(val),
426425
Err(err) => return Err(Error::Conversion(Box::new(err))),

src/util.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
use std::io;
2-
use std::io::prelude::*;
3-
41
pub fn parse_update_count(tag: String) -> u64 {
52
tag.split(' ').last().unwrap().parse().unwrap_or(0)
63
}
7-
8-
pub fn read_all<R: Read>(r: &mut R, mut buf: &mut [u8]) -> io::Result<()> {
9-
while !buf.is_empty() {
10-
match r.read(buf) {
11-
Ok(0) => return Err(io::Error::new(io::ErrorKind::Other, "unexpected EOF")),
12-
#[cfg_attr(rustfmt, rustfmt_skip)]
13-
Ok(len) => buf = &mut {buf}[len..],
14-
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
15-
Err(e) => return Err(e),
16-
}
17-
}
18-
Ok(())
19-
}

0 commit comments

Comments
 (0)