Skip to content

Commit a232889

Browse files
committed
Expand FromSql impl from just Option<T>
There's no real reason to have that requirement
1 parent e9de0b3 commit a232889

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/impls.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use postgres::types::{Type, Kind, ToSql, FromSql, Oid, IsNull, SessionInfo};
88

99
use {Array, Dimension};
1010

11-
impl<T> FromSql for Array<Option<T>> where T: FromSql {
11+
impl<T> FromSql for Array<T> where T: FromSql {
1212
fn from_sql<R: Read>(ty: &Type, raw: &mut R, info: &SessionInfo)
13-
-> postgres::Result<Array<Option<T>>> {
13+
-> postgres::Result<Array<T>> {
1414
let element_type = match ty.kind() {
1515
&Kind::Array(ref ty) => ty,
1616
_ => panic!("unexpected type {:?}", ty),
@@ -37,10 +37,10 @@ impl<T> FromSql for Array<Option<T>> where T: FromSql {
3737
for _ in 0..nele {
3838
let len = try!(raw.read_i32::<BigEndian>());
3939
if len < 0 {
40-
elements.push(None);
40+
elements.push(try!(FromSql::from_sql_null(&element_type, info)));
4141
} else {
4242
let mut limit = raw.take(len as u64);
43-
elements.push(Some(try!(FromSql::from_sql(&element_type, &mut limit, info))));
43+
elements.push(try!(FromSql::from_sql(&element_type, &mut limit, info)));
4444
if limit.limit() != 0 {
4545
let err: Box<error::Error+Sync+Send> =
4646
"from_sql call did not consume all data".into();
@@ -226,6 +226,6 @@ mod test {
226226
fn test_empty_array() {
227227
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
228228
let stmt = conn.prepare("SELECT '{}'::INT4[]").unwrap();
229-
stmt.query(&[]).unwrap().iter().next().unwrap().get::<_, Array<Option<i32>>>(0);
229+
stmt.query(&[]).unwrap().iter().next().unwrap().get::<_, Array<i32>>(0);
230230
}
231231
}

0 commit comments

Comments
 (0)