1
1
extern crate chrono;
2
2
3
- use postgres_protocol:: types;
4
3
use self :: chrono:: { DateTime , Duration , FixedOffset , Local , NaiveDate , NaiveDateTime , NaiveTime ,
5
4
Utc } ;
5
+ use postgres_protocol:: types;
6
6
use std:: error:: Error ;
7
7
8
8
use types:: { FromSql , IsNull , ToSql , Type , DATE , TIME , TIMESTAMP , TIMESTAMPTZ } ;
@@ -11,7 +11,7 @@ fn base() -> NaiveDateTime {
11
11
NaiveDate :: from_ymd ( 2000 , 1 , 1 ) . and_hms ( 0 , 0 , 0 )
12
12
}
13
13
14
- impl FromSql for NaiveDateTime {
14
+ impl < ' a > FromSql < ' a > for NaiveDateTime {
15
15
fn from_sql ( _: & Type , raw : & [ u8 ] ) -> Result < NaiveDateTime , Box < Error + Sync + Send > > {
16
16
let t = types:: timestamp_from_sql ( raw) ?;
17
17
Ok ( base ( ) + Duration :: microseconds ( t) )
@@ -34,7 +34,7 @@ impl ToSql for NaiveDateTime {
34
34
to_sql_checked ! ( ) ;
35
35
}
36
36
37
- impl FromSql for DateTime < Utc > {
37
+ impl < ' a > FromSql < ' a > for DateTime < Utc > {
38
38
fn from_sql ( type_ : & Type , raw : & [ u8 ] ) -> Result < DateTime < Utc > , Box < Error + Sync + Send > > {
39
39
let naive = NaiveDateTime :: from_sql ( type_, raw) ?;
40
40
Ok ( DateTime :: from_utc ( naive, Utc ) )
@@ -52,7 +52,7 @@ impl ToSql for DateTime<Utc> {
52
52
to_sql_checked ! ( ) ;
53
53
}
54
54
55
- impl FromSql for DateTime < Local > {
55
+ impl < ' a > FromSql < ' a > for DateTime < Local > {
56
56
fn from_sql ( type_ : & Type , raw : & [ u8 ] ) -> Result < DateTime < Local > , Box < Error + Sync + Send > > {
57
57
let utc = DateTime :: < Utc > :: from_sql ( type_, raw) ?;
58
58
Ok ( utc. with_timezone ( & Local ) )
@@ -70,7 +70,7 @@ impl ToSql for DateTime<Local> {
70
70
to_sql_checked ! ( ) ;
71
71
}
72
72
73
- impl FromSql for DateTime < FixedOffset > {
73
+ impl < ' a > FromSql < ' a > for DateTime < FixedOffset > {
74
74
fn from_sql (
75
75
type_ : & Type ,
76
76
raw : & [ u8 ] ,
@@ -91,7 +91,7 @@ impl ToSql for DateTime<FixedOffset> {
91
91
to_sql_checked ! ( ) ;
92
92
}
93
93
94
- impl FromSql for NaiveDate {
94
+ impl < ' a > FromSql < ' a > for NaiveDate {
95
95
fn from_sql ( _: & Type , raw : & [ u8 ] ) -> Result < NaiveDate , Box < Error + Sync + Send > > {
96
96
let jd = types:: date_from_sql ( raw) ?;
97
97
Ok ( base ( ) . date ( ) + Duration :: days ( jd as i64 ) )
@@ -115,7 +115,7 @@ impl ToSql for NaiveDate {
115
115
to_sql_checked ! ( ) ;
116
116
}
117
117
118
- impl FromSql for NaiveTime {
118
+ impl < ' a > FromSql < ' a > for NaiveTime {
119
119
fn from_sql ( _: & Type , raw : & [ u8 ] ) -> Result < NaiveTime , Box < Error + Sync + Send > > {
120
120
let usec = types:: time_from_sql ( raw) ?;
121
121
Ok ( NaiveTime :: from_hms ( 0 , 0 , 0 ) + Duration :: microseconds ( usec) )
0 commit comments