@@ -12,7 +12,10 @@ fn base() -> NaiveDateTime {
12
12
}
13
13
14
14
impl FromSql for NaiveDateTime {
15
- fn from_sql ( _: & Type , raw : & [ u8 ] , _: & SessionInfo ) -> Result < NaiveDateTime , Box < Error + Sync + Send > > {
15
+ fn from_sql ( _: & Type ,
16
+ raw : & [ u8 ] ,
17
+ _: & SessionInfo )
18
+ -> Result < NaiveDateTime , Box < Error + Sync + Send > > {
16
19
let t = try!( types:: timestamp_from_sql ( raw) ) ;
17
20
Ok ( base ( ) + Duration :: microseconds ( t) )
18
21
}
@@ -21,7 +24,11 @@ impl FromSql for NaiveDateTime {
21
24
}
22
25
23
26
impl ToSql for NaiveDateTime {
24
- fn to_sql ( & self , _: & Type , w : & mut Vec < u8 > , _: & SessionInfo ) -> Result < IsNull , Box < Error + Sync + Send > > {
27
+ fn to_sql ( & self ,
28
+ _: & Type ,
29
+ w : & mut Vec < u8 > ,
30
+ _: & SessionInfo )
31
+ -> Result < IsNull , Box < Error + Sync + Send > > {
25
32
let time = match ( * self - base ( ) ) . num_microseconds ( ) {
26
33
Some ( time) => time,
27
34
None => return Err ( "value too large to transmit" . into ( ) ) ,
@@ -35,7 +42,10 @@ impl ToSql for NaiveDateTime {
35
42
}
36
43
37
44
impl FromSql for DateTime < UTC > {
38
- fn from_sql ( type_ : & Type , raw : & [ u8 ] , info : & SessionInfo ) -> Result < DateTime < UTC > , Box < Error + Sync + Send > > {
45
+ fn from_sql ( type_ : & Type ,
46
+ raw : & [ u8 ] ,
47
+ info : & SessionInfo )
48
+ -> Result < DateTime < UTC > , Box < Error + Sync + Send > > {
39
49
let naive = try!( NaiveDateTime :: from_sql ( type_, raw, info) ) ;
40
50
Ok ( DateTime :: from_utc ( naive, UTC ) )
41
51
}
@@ -44,7 +54,11 @@ impl FromSql for DateTime<UTC> {
44
54
}
45
55
46
56
impl ToSql for DateTime < UTC > {
47
- fn to_sql ( & self , type_ : & Type , w : & mut Vec < u8 > , info : & SessionInfo ) -> Result < IsNull , Box < Error + Sync + Send > > {
57
+ fn to_sql ( & self ,
58
+ type_ : & Type ,
59
+ w : & mut Vec < u8 > ,
60
+ info : & SessionInfo )
61
+ -> Result < IsNull , Box < Error + Sync + Send > > {
48
62
self . naive_utc ( ) . to_sql ( type_, w, info)
49
63
}
50
64
@@ -53,7 +67,10 @@ impl ToSql for DateTime<UTC> {
53
67
}
54
68
55
69
impl FromSql for DateTime < Local > {
56
- fn from_sql ( type_ : & Type , raw : & [ u8 ] , info : & SessionInfo ) -> Result < DateTime < Local > , Box < Error + Sync + Send > > {
70
+ fn from_sql ( type_ : & Type ,
71
+ raw : & [ u8 ] ,
72
+ info : & SessionInfo )
73
+ -> Result < DateTime < Local > , Box < Error + Sync + Send > > {
57
74
let utc = try!( DateTime :: < UTC > :: from_sql ( type_, raw, info) ) ;
58
75
Ok ( utc. with_timezone ( & Local ) )
59
76
}
@@ -62,7 +79,11 @@ impl FromSql for DateTime<Local> {
62
79
}
63
80
64
81
impl ToSql for DateTime < Local > {
65
- fn to_sql ( & self , type_ : & Type , mut w : & mut Vec < u8 > , info : & SessionInfo ) -> Result < IsNull , Box < Error + Sync + Send > > {
82
+ fn to_sql ( & self ,
83
+ type_ : & Type ,
84
+ mut w : & mut Vec < u8 > ,
85
+ info : & SessionInfo )
86
+ -> Result < IsNull , Box < Error + Sync + Send > > {
66
87
self . with_timezone ( & UTC ) . to_sql ( type_, w, info)
67
88
}
68
89
@@ -71,7 +92,10 @@ impl ToSql for DateTime<Local> {
71
92
}
72
93
73
94
impl FromSql for DateTime < FixedOffset > {
74
- fn from_sql ( type_ : & Type , raw : & [ u8 ] , info : & SessionInfo ) -> Result < DateTime < FixedOffset > , Box < Error + Sync + Send > > {
95
+ fn from_sql ( type_ : & Type ,
96
+ raw : & [ u8 ] ,
97
+ info : & SessionInfo )
98
+ -> Result < DateTime < FixedOffset > , Box < Error + Sync + Send > > {
75
99
let utc = try!( DateTime :: < UTC > :: from_sql ( type_, raw, info) ) ;
76
100
Ok ( utc. with_timezone ( & FixedOffset :: east ( 0 ) ) )
77
101
}
@@ -80,7 +104,11 @@ impl FromSql for DateTime<FixedOffset> {
80
104
}
81
105
82
106
impl ToSql for DateTime < FixedOffset > {
83
- fn to_sql ( & self , type_ : & Type , w : & mut Vec < u8 > , info : & SessionInfo ) -> Result < IsNull , Box < Error + Sync + Send > > {
107
+ fn to_sql ( & self ,
108
+ type_ : & Type ,
109
+ w : & mut Vec < u8 > ,
110
+ info : & SessionInfo )
111
+ -> Result < IsNull , Box < Error + Sync + Send > > {
84
112
self . with_timezone ( & UTC ) . to_sql ( type_, w, info)
85
113
}
86
114
@@ -89,7 +117,10 @@ impl ToSql for DateTime<FixedOffset> {
89
117
}
90
118
91
119
impl FromSql for NaiveDate {
92
- fn from_sql ( _: & Type , raw : & [ u8 ] , _: & SessionInfo ) -> Result < NaiveDate , Box < Error + Sync + Send > > {
120
+ fn from_sql ( _: & Type ,
121
+ raw : & [ u8 ] ,
122
+ _: & SessionInfo )
123
+ -> Result < NaiveDate , Box < Error + Sync + Send > > {
93
124
let jd = try!( types:: date_from_sql ( raw) ) ;
94
125
Ok ( base ( ) . date ( ) + Duration :: days ( jd as i64 ) )
95
126
}
@@ -98,7 +129,11 @@ impl FromSql for NaiveDate {
98
129
}
99
130
100
131
impl ToSql for NaiveDate {
101
- fn to_sql ( & self , _: & Type , w : & mut Vec < u8 > , _: & SessionInfo ) -> Result < IsNull , Box < Error + Sync + Send > > {
132
+ fn to_sql ( & self ,
133
+ _: & Type ,
134
+ w : & mut Vec < u8 > ,
135
+ _: & SessionInfo )
136
+ -> Result < IsNull , Box < Error + Sync + Send > > {
102
137
let jd = ( * self - base ( ) . date ( ) ) . num_days ( ) ;
103
138
if jd > i32:: max_value ( ) as i64 || jd < i32:: min_value ( ) as i64 {
104
139
return Err ( "value too large to transmit" . into ( ) ) ;
@@ -113,7 +148,10 @@ impl ToSql for NaiveDate {
113
148
}
114
149
115
150
impl FromSql for NaiveTime {
116
- fn from_sql ( _: & Type , raw : & [ u8 ] , _: & SessionInfo ) -> Result < NaiveTime , Box < Error + Sync + Send > > {
151
+ fn from_sql ( _: & Type ,
152
+ raw : & [ u8 ] ,
153
+ _: & SessionInfo )
154
+ -> Result < NaiveTime , Box < Error + Sync + Send > > {
117
155
let usec = try!( types:: time_from_sql ( raw) ) ;
118
156
Ok ( NaiveTime :: from_hms ( 0 , 0 , 0 ) + Duration :: microseconds ( usec) )
119
157
}
@@ -122,7 +160,11 @@ impl FromSql for NaiveTime {
122
160
}
123
161
124
162
impl ToSql for NaiveTime {
125
- fn to_sql ( & self , _: & Type , w : & mut Vec < u8 > , _: & SessionInfo ) -> Result < IsNull , Box < Error + Sync + Send > > {
163
+ fn to_sql ( & self ,
164
+ _: & Type ,
165
+ w : & mut Vec < u8 > ,
166
+ _: & SessionInfo )
167
+ -> Result < IsNull , Box < Error + Sync + Send > > {
126
168
let delta = * self - NaiveTime :: from_hms ( 0 , 0 , 0 ) ;
127
169
let time = match delta. num_microseconds ( ) {
128
170
Some ( time) => time,
0 commit comments