File tree 2 files changed +17
-7
lines changed
2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -164,7 +164,10 @@ impl Row {
164
164
165
165
let ty = self . columns ( ) [ idx] . type_ ( ) ;
166
166
if !T :: accepts ( ty) {
167
- return Err ( Error :: from_sql ( Box :: new ( WrongType :: new ( ty. clone ( ) ) ) , idx) ) ;
167
+ return Err ( Error :: from_sql (
168
+ Box :: new ( WrongType :: new :: < T > ( ty. clone ( ) ) ) ,
169
+ idx,
170
+ ) ) ;
168
171
}
169
172
170
173
let buf = self . ranges [ idx] . clone ( ) . map ( |r| & self . body . buffer ( ) [ r] ) ;
Original file line number Diff line number Diff line change 68
68
T : ToSql ,
69
69
{
70
70
if !T :: accepts ( ty) {
71
- return Err ( Box :: new ( WrongType ( ty. clone ( ) ) ) ) ;
71
+ return Err ( Box :: new ( WrongType :: new :: < T > ( ty. clone ( ) ) ) ) ;
72
72
}
73
73
v. to_sql ( ty, out)
74
74
}
@@ -91,6 +91,7 @@ mod type_gen;
91
91
92
92
#[ cfg( feature = "with-serde_json-1" ) ]
93
93
pub use crate :: types:: serde_json_1:: Json ;
94
+ use std:: any:: type_name;
94
95
95
96
/// A Postgres type.
96
97
#[ derive( PartialEq , Eq , Clone , Debug ) ]
@@ -206,23 +207,29 @@ impl Error for WasNull {}
206
207
/// An error indicating that a conversion was attempted between incompatible
207
208
/// Rust and Postgres types.
208
209
#[ derive( Debug ) ]
209
- pub struct WrongType ( Type ) ;
210
+ pub struct WrongType {
211
+ postgres : Type ,
212
+ rust : & ' static str ,
213
+ }
210
214
211
215
impl fmt:: Display for WrongType {
212
216
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
213
217
write ! (
214
218
fmt,
215
- "cannot convert to or from a Postgres value of type `{}`" ,
216
- self . 0
219
+ "cannot convert between the Rust type `{}` and the Postgres type `{}`" ,
220
+ self . rust , self . postgres ,
217
221
)
218
222
}
219
223
}
220
224
221
225
impl Error for WrongType { }
222
226
223
227
impl WrongType {
224
- pub ( crate ) fn new ( ty : Type ) -> WrongType {
225
- WrongType ( ty)
228
+ pub ( crate ) fn new < T > ( ty : Type ) -> WrongType {
229
+ WrongType {
230
+ postgres : ty,
231
+ rust : type_name :: < T > ( ) ,
232
+ }
226
233
}
227
234
}
228
235
You can’t perform that action at this time.
0 commit comments