This commit is contained in:
Steven Fackler
2016-06-15 21:38:07 -07:00
parent 4ab349ae5f
commit e350c05124
3 changed files with 5 additions and 19 deletions

View File

@@ -1,6 +1,5 @@
extern crate chrono;
use std::error;
use std::io::prelude::*;
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
use self::chrono::{Duration, NaiveDate, NaiveTime, NaiveDateTime, DateTime, UTC, Local,
@@ -31,10 +30,7 @@ impl ToSql for NaiveDateTime {
-> Result<IsNull> {
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));
}
None => return Err(Error::Conversion("value too large to transmit".into())),
};
try!(w.write_i64::<BigEndian>(time));
Ok(IsNull::No)
@@ -130,8 +126,7 @@ impl ToSql for NaiveDate {
-> Result<IsNull> {
let jd = (*self - base().date()).num_days();
if jd > i32::max_value() as i64 || jd < i32::min_value() as i64 {
let err: Box<error::Error + Sync + Send> = "value too large to transmit".into();
return Err(Error::Conversion(err));
return Err(Error::Conversion("value too large to transmit".into()));
}
try!(w.write_i32::<BigEndian>(jd as i32));
@@ -160,10 +155,7 @@ impl ToSql for NaiveTime {
let delta = *self - NaiveTime::from_hms(0, 0, 0);
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));
}
None => return Err(Error::Conversion("value too large to transmit".into())),
};
try!(w.write_i64::<BigEndian>(time));
Ok(IsNull::No)

View File

@@ -1,7 +1,6 @@
extern crate rustc_serialize;
use self::rustc_serialize::json;
use std::error;
use std::io::prelude::*;
use byteorder::{ReadBytesExt, WriteBytesExt};
@@ -14,9 +13,7 @@ impl FromSql for json::Json {
if let Type::Jsonb = *ty {
// We only support version 1 of the jsonb binary format
if try!(raw.read_u8()) != 1 {
let err: Box<error::Error + Sync + Send> = "unsupported JSONB encoding version"
.into();
return Err(Error::Conversion(err));
return Err(Error::Conversion("unsupported JSONB encoding version".into()));
}
}
json::Json::from_reader(raw).map_err(|err| Error::Conversion(Box::new(err)))

View File

@@ -1,6 +1,5 @@
extern crate serde_json;
use std::error;
use std::io::prelude::*;
use byteorder::{ReadBytesExt, WriteBytesExt};
use self::serde_json::Value;
@@ -14,9 +13,7 @@ impl FromSql for Value {
if let Type::Jsonb = *ty {
// We only support version 1 of the jsonb binary format
if try!(raw.read_u8()) != 1 {
let err: Box<error::Error + Sync + Send> = "unsupported JSONB encoding version"
.into();
return Err(Error::Conversion(err));
return Err(Error::Conversion("unsupported JSONB encoding version".into()));
}
}
serde_json::de::from_reader(raw).map_err(|err| Error::Conversion(Box::new(err)))