Fix unwraps in chrono impls

This commit is contained in:
Steven Fackler 2015-08-09 23:32:54 -04:00
parent 9a7c4ce811
commit 67e4a12752
2 changed files with 20 additions and 5 deletions

View File

@ -322,7 +322,8 @@ impl<R: BufRead> ReadMessage for R {
b't' => try!(read_parameter_description(&mut rdr)),
b'T' => try!(read_row_description(&mut rdr)),
b'Z' => ReadyForQuery { _state: try!(rdr.read_u8()) },
_ => return Err(io::Error::new(io::ErrorKind::Other, "unexpected message tag")),
t => return Err(io::Error::new(io::ErrorKind::Other,
format!("unexpected message tag `{}`", t))),
};
if rdr.limit() != 0 {
return Err(io::Error::new(io::ErrorKind::Other, "didn't read entire message"));
@ -377,7 +378,8 @@ fn read_auth_message<R: Read>(buf: &mut R) -> io::Result<BackendMessage> {
6 => AuthenticationSCMCredential,
7 => AuthenticationGSS,
9 => AuthenticationSSPI,
_ => return Err(io::Error::new(io::ErrorKind::Other, "unexpected authentication tag")),
t => return Err(io::Error::new(io::ErrorKind::Other,
format!("unexpected authentication tag `{}`", t))),
})
}

View File

@ -24,8 +24,14 @@ impl FromSql for NaiveDateTime {
impl ToSql for NaiveDateTime {
fn to_sql<W: Write+?Sized>(&self, _: &Type, mut w: &mut W, _: &SessionInfo) -> Result<IsNull> {
let t = (*self - base()).num_microseconds().unwrap();
try!(w.write_i64::<BigEndian>(t));
let time = match (*self - base()).num_microseconds() {
Some(time) => time,
None => {
let err: Box<error::Error+Sync+Send> = "value too large to transmit".into();
return Err(Error::Conversion(err));
}
};
try!(w.write_i64::<BigEndian>(time));
Ok(IsNull::No)
}
@ -128,7 +134,14 @@ impl FromSql for NaiveTime {
impl ToSql for NaiveTime {
fn to_sql<W: Write+?Sized>(&self, _: &Type, mut w: &mut W, _: &SessionInfo) -> Result<IsNull> {
let delta = *self - NaiveTime::from_hms(0, 0, 0);
try!(w.write_i64::<BigEndian>(delta.num_microseconds().unwrap()));
let time = match delta.num_microseconds() {
Some(time) => time,
None => {
let err: Box<error::Error+Sync+Send> = "value too large to transmit".into();
return Err(Error::Conversion(err));
}
};
try!(w.write_i64::<BigEndian>(time));
Ok(IsNull::No)
}