@@ -9,6 +9,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
9
9
10
10
pub use self :: slice:: Slice ;
11
11
pub use self :: types:: Type ;
12
+ pub use self :: special:: { Date , Timestamp } ;
12
13
use { Result , SessionInfoNew , InnerConnection , OtherNew , WrongTypeNew , FieldNew } ;
13
14
use error:: Error ;
14
15
@@ -70,6 +71,7 @@ mod chrono;
70
71
#[ cfg( feature = "eui48" ) ]
71
72
mod eui48;
72
73
74
+ mod special;
73
75
mod types;
74
76
75
77
/// A structure providing information for conversion methods.
@@ -256,41 +258,41 @@ impl WrongTypeNew for WrongType {
256
258
/// The following implementations are provided by this crate, along with the
257
259
/// corresponding Postgres types:
258
260
///
259
- /// | Rust type | Postgres type(s) |
260
- /// |----------------------------------------------- |--------------------------------|
261
- /// | `bool` | BOOL |
262
- /// | `i8` | "char" |
263
- /// | `i16` | SMALLINT, SMALLSERIAL |
264
- /// | `i32` | INT, SERIAL |
265
- /// | `u32` | OID |
266
- /// | `i64` | BIGINT, BIGSERIAL |
267
- /// | `f32` | REAL |
268
- /// | `f64` | DOUBLE PRECISION |
269
- /// | `String` | VARCHAR, CHAR(n), TEXT, CITEXT |
270
- /// | `Vec<u8>` | BYTEA |
271
- /// | `HashMap< String, Option< String>> ` | HSTORE |
261
+ /// | Rust type | Postgres type(s) |
262
+ /// |-----------------------------------|--------------------------------|
263
+ /// | `bool` | BOOL |
264
+ /// | `i8` | "char" |
265
+ /// | `i16` | SMALLINT, SMALLSERIAL |
266
+ /// | `i32` | INT, SERIAL |
267
+ /// | `u32` | OID |
268
+ /// | `i64` | BIGINT, BIGSERIAL |
269
+ /// | `f32` | REAL |
270
+ /// | `f64` | DOUBLE PRECISION |
271
+ /// | `String` | VARCHAR, CHAR(n), TEXT, CITEXT |
272
+ /// | `Vec<u8>` | BYTEA |
273
+ /// | `HashMap< String, Option< String>> ` | HSTORE |
272
274
///
273
275
/// In addition, some implementations are provided for types in third party
274
276
/// crates. These are disabled by default; to opt into one of these
275
277
/// implementations, activate the Cargo feature corresponding to the crate's
276
278
/// name. For example, the `serde_json` feature enables the implementation for
277
279
/// the `serde_json::Value` type.
278
280
///
279
- /// | Rust type | Postgres type(s) |
280
- /// |--------------------------------------- |-------------------------------------|
281
- /// | `serialize::json::Json` | JSON, JSONB |
282
- /// | `serde_json::Value` | JSON, JSONB |
283
- /// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
284
- /// | `chrono::NaiveDateTime` | TIMESTAMP |
285
- /// | `chrono::DateTime< UTC> ` | TIMESTAMP WITH TIME ZONE |
286
- /// | `chrono::DateTime< Local> ` | TIMESTAMP WITH TIME ZONE |
287
- /// | `chrono::DateTime< FixedOffset> ` | TIMESTAMP WITH TIME ZONE |
288
- /// | `chrono::NaiveDate` | DATE |
289
- /// | `chrono::NaiveTime` | TIME |
290
- /// | `eui48::MacAddress` | MACADDR |
291
- /// | `uuid::Uuid` | UUID |
292
- /// | `bit_vec::BitVec` | BIT, VARBIT |
293
- /// | `eui48::MacAddress` | MACADDR |
281
+ /// | Rust type | Postgres type(s) |
282
+ /// |---------------------------------|-------------------------------------|
283
+ /// | `serialize::json::Json` | JSON, JSONB |
284
+ /// | `serde_json::Value` | JSON, JSONB |
285
+ /// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
286
+ /// | `chrono::NaiveDateTime` | TIMESTAMP |
287
+ /// | `chrono::DateTime< UTC> ` | TIMESTAMP WITH TIME ZONE |
288
+ /// | `chrono::DateTime< Local> ` | TIMESTAMP WITH TIME ZONE |
289
+ /// | `chrono::DateTime< FixedOffset> ` | TIMESTAMP WITH TIME ZONE |
290
+ /// | `chrono::NaiveDate` | DATE |
291
+ /// | `chrono::NaiveTime` | TIME |
292
+ /// | `eui48::MacAddress` | MACADDR |
293
+ /// | `uuid::Uuid` | UUID |
294
+ /// | `bit_vec::BitVec` | BIT, VARBIT |
295
+ /// | `eui48::MacAddress` | MACADDR |
294
296
///
295
297
/// # Nullability
296
298
///
@@ -356,13 +358,18 @@ impl<T: FromSql> FromSql for Vec<T> {
356
358
_ => panic ! ( "expected array type" ) ,
357
359
} ;
358
360
359
- if try!( raw. read_i32 :: < BigEndian > ( ) ) != 1 {
361
+ let dimensions = try!( raw. read_i32 :: < BigEndian > ( ) ) ;
362
+ if dimensions > 1 {
360
363
return Err ( Error :: Conversion ( "array contains too many dimensions" . into ( ) ) ) ;
361
364
}
362
365
363
366
let _has_nulls = try!( raw. read_i32 :: < BigEndian > ( ) ) ;
364
367
let _member_oid = try!( raw. read_u32 :: < BigEndian > ( ) ) ;
365
368
369
+ if dimensions == 0 {
370
+ return Ok ( vec ! [ ] ) ;
371
+ }
372
+
366
373
let count = try!( raw. read_i32 :: < BigEndian > ( ) ) ;
367
374
let _index_offset = try!( raw. read_i32 :: < BigEndian > ( ) ) ;
368
375
@@ -501,42 +508,42 @@ pub enum IsNull {
501
508
/// The following implementations are provided by this crate, along with the
502
509
/// corresponding Postgres types:
503
510
///
504
- /// | Rust type | Postgres type(s) |
505
- /// |----------------------------------------------- |--------------------------------|
506
- /// | `bool` | BOOL |
507
- /// | `i8` | "char" |
508
- /// | `i16` | SMALLINT, SMALLSERIAL |
509
- /// | `i32` | INT, SERIAL |
510
- /// | `u32` | OID |
511
- /// | `i64` | BIGINT, BIGSERIAL |
512
- /// | `f32` | REAL |
513
- /// | `f64` | DOUBLE PRECISION |
514
- /// | `String` | VARCHAR, CHAR(n), TEXT, CITEXT |
515
- /// | `&str` | VARCHAR, CHAR(n), TEXT, CITEXT |
516
- /// | `Vec<u8>` | BYTEA |
517
- /// | `&[u8]` | BYTEA |
518
- /// | `HashMap< String, Option< String>> ` | HSTORE |
511
+ /// | Rust type | Postgres type(s) |
512
+ /// |-----------------------------------|--------------------------------|
513
+ /// | `bool` | BOOL |
514
+ /// | `i8` | "char" |
515
+ /// | `i16` | SMALLINT, SMALLSERIAL |
516
+ /// | `i32` | INT, SERIAL |
517
+ /// | `u32` | OID |
518
+ /// | `i64` | BIGINT, BIGSERIAL |
519
+ /// | `f32` | REAL |
520
+ /// | `f64` | DOUBLE PRECISION |
521
+ /// | `String` | VARCHAR, CHAR(n), TEXT, CITEXT |
522
+ /// | `&str` | VARCHAR, CHAR(n), TEXT, CITEXT |
523
+ /// | `Vec<u8>` | BYTEA |
524
+ /// | `&[u8]` | BYTEA |
525
+ /// | `HashMap< String, Option< String>> ` | HSTORE |
519
526
///
520
527
/// In addition, some implementations are provided for types in third party
521
528
/// crates. These are disabled by default; to opt into one of these
522
529
/// implementations, activate the Cargo feature corresponding to the crate's
523
530
/// name. For example, the `serde_json` feature enables the implementation for
524
531
/// the `serde_json::Value` type.
525
532
///
526
- /// | Rust type | Postgres type(s) |
527
- /// |--------------------------------------- |-------------------------------------|
528
- /// | `serialize::json::Json` | JSON, JSONB |
529
- /// | `serde_json::Value` | JSON, JSONB |
530
- /// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
531
- /// | `chrono::NaiveDateTime` | TIMESTAMP |
532
- /// | `chrono::DateTime< UTC> ` | TIMESTAMP WITH TIME ZONE |
533
- /// | `chrono::DateTime< Local> ` | TIMESTAMP WITH TIME ZONE |
534
- /// | `chrono::DateTime< FixedOffset> ` | TIMESTAMP WITH TIME ZONE |
535
- /// | `chrono::NaiveDate` | DATE |
536
- /// | `chrono::NaiveTime` | TIME |
537
- /// | `uuid::Uuid` | UUID |
538
- /// | `bit_vec::BitVec` | BIT, VARBIT |
539
- /// | `eui48::MacAddress` | MACADDR |
533
+ /// | Rust type | Postgres type(s) |
534
+ /// |---------------------------------|-------------------------------------|
535
+ /// | `serialize::json::Json` | JSON, JSONB |
536
+ /// | `serde_json::Value` | JSON, JSONB |
537
+ /// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
538
+ /// | `chrono::NaiveDateTime` | TIMESTAMP |
539
+ /// | `chrono::DateTime< UTC> ` | TIMESTAMP WITH TIME ZONE |
540
+ /// | `chrono::DateTime< Local> ` | TIMESTAMP WITH TIME ZONE |
541
+ /// | `chrono::DateTime< FixedOffset> ` | TIMESTAMP WITH TIME ZONE |
542
+ /// | `chrono::NaiveDate` | DATE |
543
+ /// | `chrono::NaiveTime` | TIME |
544
+ /// | `uuid::Uuid` | UUID |
545
+ /// | `bit_vec::BitVec` | BIT, VARBIT |
546
+ /// | `eui48::MacAddress` | MACADDR |
540
547
///
541
548
/// # Nullability
542
549
///
@@ -806,8 +813,7 @@ impl ToSql for HashMap<String, Option<String>> {
806
813
807
814
fn downcast ( len : usize ) -> Result < i32 > {
808
815
if len > i32:: max_value ( ) as usize {
809
- let err: Box < error:: Error + Sync + Send > = "value too large to transmit" . into ( ) ;
810
- Err ( Error :: Conversion ( err) )
816
+ Err ( Error :: Conversion ( "value too large to transmit" . into ( ) ) )
811
817
} else {
812
818
Ok ( len as i32 )
813
819
}
0 commit comments