@@ -156,11 +156,11 @@ impl Other {
156
156
#[ doc( hidden) ]
157
157
pub fn new ( name : String , oid : Oid , kind : Kind , schema : String ) -> Other {
158
158
Other ( Arc :: new ( OtherInner {
159
- name : name,
160
- oid : oid,
161
- kind : kind,
162
- schema : schema,
163
- } ) )
159
+ name : name,
160
+ oid : oid,
161
+ kind : kind,
162
+ schema : schema,
163
+ } ) )
164
164
}
165
165
}
166
166
@@ -236,19 +236,19 @@ impl WrongType {
236
236
/// The following implementations are provided by this crate, along with the
237
237
/// corresponding Postgres types:
238
238
///
239
- /// | Rust type | Postgres type(s) |
240
- /// |-----------------------------------|--------------------------------------|
241
- /// | `bool` | BOOL |
242
- /// | `i8` | "char" |
243
- /// | `i16` | SMALLINT, SMALLSERIAL |
244
- /// | `i32` | INT, SERIAL |
245
- /// | `u32` | OID |
246
- /// | `i64` | BIGINT, BIGSERIAL |
247
- /// | `f32` | REAL |
248
- /// | `f64` | DOUBLE PRECISION |
249
- /// | `String` | VARCHAR, CHAR(n), TEXT, CITEXT, NAME |
250
- /// | `Vec<u8>` | BYTEA |
251
- /// | `HashMap<String, Option<String>>` | HSTORE |
239
+ /// | Rust type | Postgres type(s) |
240
+ /// |-----------------------------------|----------------------------------------------- |
241
+ /// | `bool` | BOOL |
242
+ /// | `i8` | "char" |
243
+ /// | `i16` | SMALLINT, SMALLSERIAL |
244
+ /// | `i32` | INT, SERIAL |
245
+ /// | `u32` | OID |
246
+ /// | `i64` | BIGINT, BIGSERIAL |
247
+ /// | `f32` | REAL |
248
+ /// | `f64` | DOUBLE PRECISION |
249
+ /// | `String` | VARCHAR, CHAR(n), TEXT, CITEXT, NAME, UNKNOWN |
250
+ /// | `Vec<u8>` | BYTEA |
251
+ /// | `HashMap<String, Option<String>>` | HSTORE |
252
252
///
253
253
/// In addition, some implementations are provided for types in third party
254
254
/// crates. These are disabled by default; to opt into one of these
@@ -288,9 +288,7 @@ pub trait FromSql: Sized {
288
288
///
289
289
/// The caller of this method is responsible for ensuring that this type
290
290
/// is compatible with the Postgres `Type`.
291
- fn from_sql ( ty : & Type ,
292
- raw : & [ u8 ] )
293
- -> Result < Self , Box < Error + Sync + Send > > ;
291
+ fn from_sql ( ty : & Type , raw : & [ u8 ] ) -> Result < Self , Box < Error + Sync + Send > > ;
294
292
295
293
/// Creates a new value of this type from a `NULL` SQL value.
296
294
///
@@ -306,9 +304,7 @@ pub trait FromSql: Sized {
306
304
307
305
/// A convenience function that delegates to `from_sql` and `from_sql_null` depending on the
308
306
/// value of `raw`.
309
- fn from_sql_nullable ( ty : & Type ,
310
- raw : Option < & [ u8 ] > )
311
- -> Result < Self , Box < Error + Sync + Send > > {
307
+ fn from_sql_nullable ( ty : & Type , raw : Option < & [ u8 ] > ) -> Result < Self , Box < Error + Sync + Send > > {
312
308
match raw {
313
309
Some ( raw) => Self :: from_sql ( ty, raw) ,
314
310
None => Self :: from_sql_null ( ty) ,
@@ -321,9 +317,7 @@ pub trait FromSql: Sized {
321
317
}
322
318
323
319
impl < T : FromSql > FromSql for Option < T > {
324
- fn from_sql ( ty : & Type ,
325
- raw : & [ u8 ] )
326
- -> Result < Option < T > , Box < Error + Sync + Send > > {
320
+ fn from_sql ( ty : & Type , raw : & [ u8 ] ) -> Result < Option < T > , Box < Error + Sync + Send > > {
327
321
<T as FromSql >:: from_sql ( ty, raw) . map ( Some )
328
322
}
329
323
@@ -337,9 +331,7 @@ impl<T: FromSql> FromSql for Option<T> {
337
331
}
338
332
339
333
impl < T : FromSql > FromSql for Vec < T > {
340
- fn from_sql ( ty : & Type ,
341
- raw : & [ u8 ] )
342
- -> Result < Vec < T > , Box < Error + Sync + Send > > {
334
+ fn from_sql ( ty : & Type , raw : & [ u8 ] ) -> Result < Vec < T > , Box < Error + Sync + Send > > {
343
335
let member_type = match * ty. kind ( ) {
344
336
Kind :: Array ( ref member) => member,
345
337
_ => panic ! ( "expected array type" ) ,
@@ -350,7 +342,8 @@ impl<T: FromSql> FromSql for Vec<T> {
350
342
return Err ( "array contains too many dimensions" . into ( ) ) ;
351
343
}
352
344
353
- array. values ( )
345
+ array
346
+ . values ( )
354
347
. and_then ( |v| T :: from_sql_nullable ( member_type, v) )
355
348
. collect ( )
356
349
}
@@ -364,9 +357,7 @@ impl<T: FromSql> FromSql for Vec<T> {
364
357
}
365
358
366
359
impl FromSql for Vec < u8 > {
367
- fn from_sql ( _: & Type ,
368
- raw : & [ u8 ] )
369
- -> Result < Vec < u8 > , Box < Error + Sync + Send > > {
360
+ fn from_sql ( _: & Type , raw : & [ u8 ] ) -> Result < Vec < u8 > , Box < Error + Sync + Send > > {
370
361
Ok ( types:: bytea_from_sql ( raw) . to_owned ( ) )
371
362
}
372
363
@@ -380,7 +371,7 @@ impl FromSql for String {
380
371
381
372
fn accepts ( ty : & Type ) -> bool {
382
373
match * ty {
383
- Type :: Varchar | Type :: Text | Type :: Bpchar | Type :: Name => true ,
374
+ Type :: Varchar | Type :: Text | Type :: Bpchar | Type :: Name | Type :: Unknown => true ,
384
375
Type :: Other ( ref u) if u. name ( ) == "citext" => true ,
385
376
_ => false ,
386
377
}
@@ -500,10 +491,7 @@ pub trait ToSql: fmt::Debug {
500
491
/// The return value indicates if this value should be represented as
501
492
/// `NULL`. If this is the case, implementations **must not** write
502
493
/// anything to `out`.
503
- fn to_sql ( & self ,
504
- ty : & Type ,
505
- out : & mut Vec < u8 > )
506
- -> Result < IsNull , Box < Error + Sync + Send > >
494
+ fn to_sql ( & self , ty : & Type , out : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > >
507
495
where Self : Sized ;
508
496
509
497
/// Determines if a value of this type can be converted to the specified
@@ -523,10 +511,7 @@ pub trait ToSql: fmt::Debug {
523
511
impl < ' a , T > ToSql for & ' a T
524
512
where T : ToSql
525
513
{
526
- fn to_sql ( & self ,
527
- ty : & Type ,
528
- out : & mut Vec < u8 > )
529
- -> Result < IsNull , Box < Error + Sync + Send > > {
514
+ fn to_sql ( & self , ty : & Type , out : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
530
515
( * self ) . to_sql ( ty, out)
531
516
}
532
517
@@ -538,10 +523,7 @@ impl<'a, T> ToSql for &'a T
538
523
}
539
524
540
525
impl < T : ToSql > ToSql for Option < T > {
541
- fn to_sql ( & self ,
542
- ty : & Type ,
543
- out : & mut Vec < u8 > )
544
- -> Result < IsNull , Box < Error + Sync + Send > > {
526
+ fn to_sql ( & self , ty : & Type , out : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
545
527
match * self {
546
528
Some ( ref val) => val. to_sql ( ty, out) ,
547
529
None => Ok ( IsNull :: Yes ) ,
@@ -556,10 +538,7 @@ impl<T: ToSql> ToSql for Option<T> {
556
538
}
557
539
558
540
impl < ' a , T : ToSql > ToSql for & ' a [ T ] {
559
- fn to_sql ( & self ,
560
- ty : & Type ,
561
- w : & mut Vec < u8 > )
562
- -> Result < IsNull , Box < Error + Sync + Send > > {
541
+ fn to_sql ( & self , ty : & Type , w : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
563
542
let member_type = match * ty. kind ( ) {
564
543
Kind :: Array ( ref member) => member,
565
544
_ => panic ! ( "expected array type" ) ,
@@ -571,16 +550,14 @@ impl<'a, T: ToSql> ToSql for &'a [T] {
571
550
} ;
572
551
573
552
types:: array_to_sql ( Some ( dimension) ,
574
- true ,
575
- member_type. oid ( ) ,
576
- self . iter ( ) ,
577
- |e, w| {
578
- match e. to_sql ( member_type, w) ? {
579
- IsNull :: No => Ok ( postgres_protocol:: IsNull :: No ) ,
580
- IsNull :: Yes => Ok ( postgres_protocol:: IsNull :: Yes ) ,
581
- }
582
- } ,
583
- w) ?;
553
+ true ,
554
+ member_type. oid ( ) ,
555
+ self . iter ( ) ,
556
+ |e, w| match e. to_sql ( member_type, w) ? {
557
+ IsNull :: No => Ok ( postgres_protocol:: IsNull :: No ) ,
558
+ IsNull :: Yes => Ok ( postgres_protocol:: IsNull :: Yes ) ,
559
+ } ,
560
+ w) ?;
584
561
Ok ( IsNull :: No )
585
562
}
586
563
@@ -595,10 +572,7 @@ impl<'a, T: ToSql> ToSql for &'a [T] {
595
572
}
596
573
597
574
impl < ' a > ToSql for & ' a [ u8 ] {
598
- fn to_sql ( & self ,
599
- _: & Type ,
600
- w : & mut Vec < u8 > )
601
- -> Result < IsNull , Box < Error + Sync + Send > > {
575
+ fn to_sql ( & self , _: & Type , w : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
602
576
types:: bytea_to_sql ( * self , w) ;
603
577
Ok ( IsNull :: No )
604
578
}
@@ -609,10 +583,7 @@ impl<'a> ToSql for &'a [u8] {
609
583
}
610
584
611
585
impl < T : ToSql > ToSql for Vec < T > {
612
- fn to_sql ( & self ,
613
- ty : & Type ,
614
- w : & mut Vec < u8 > )
615
- -> Result < IsNull , Box < Error + Sync + Send > > {
586
+ fn to_sql ( & self , ty : & Type , w : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
616
587
<& [ T ] as ToSql >:: to_sql ( & & * * self , ty, w)
617
588
}
618
589
@@ -624,10 +595,7 @@ impl<T: ToSql> ToSql for Vec<T> {
624
595
}
625
596
626
597
impl ToSql for Vec < u8 > {
627
- fn to_sql ( & self ,
628
- ty : & Type ,
629
- w : & mut Vec < u8 > )
630
- -> Result < IsNull , Box < Error + Sync + Send > > {
598
+ fn to_sql ( & self , ty : & Type , w : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
631
599
<& [ u8 ] as ToSql >:: to_sql ( & & * * self , ty, w)
632
600
}
633
601
@@ -639,10 +607,7 @@ impl ToSql for Vec<u8> {
639
607
}
640
608
641
609
impl < ' a > ToSql for & ' a str {
642
- fn to_sql ( & self ,
643
- _: & Type ,
644
- w : & mut Vec < u8 > )
645
- -> Result < IsNull , Box < Error + Sync + Send > > {
610
+ fn to_sql ( & self , _: & Type , w : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
646
611
types:: text_to_sql ( * self , w) ;
647
612
Ok ( IsNull :: No )
648
613
}
@@ -659,10 +624,7 @@ impl<'a> ToSql for &'a str {
659
624
}
660
625
661
626
impl ToSql for String {
662
- fn to_sql ( & self ,
663
- ty : & Type ,
664
- w : & mut Vec < u8 > )
665
- -> Result < IsNull , Box < Error + Sync + Send > > {
627
+ fn to_sql ( & self , ty : & Type , w : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
666
628
<& str as ToSql >:: to_sql ( & & * * self , ty, w)
667
629
}
668
630
@@ -701,11 +663,9 @@ simple_to!(f32, float4_to_sql, Type::Float4);
701
663
simple_to ! ( f64 , float8_to_sql, Type :: Float8 ) ;
702
664
703
665
impl ToSql for HashMap < String , Option < String > > {
704
- fn to_sql ( & self ,
705
- _: & Type ,
706
- w : & mut Vec < u8 > )
707
- -> Result < IsNull , Box < Error + Sync + Send > > {
708
- types:: hstore_to_sql ( self . iter ( ) . map ( |( k, v) | ( & * * k, v. as_ref ( ) . map ( |v| & * * v) ) ) , w) ?;
666
+ fn to_sql ( & self , _: & Type , w : & mut Vec < u8 > ) -> Result < IsNull , Box < Error + Sync + Send > > {
667
+ types:: hstore_to_sql ( self . iter ( ) . map ( |( k, v) | ( & * * k, v. as_ref ( ) . map ( |v| & * * v) ) ) ,
668
+ w) ?;
709
669
Ok ( IsNull :: No )
710
670
}
711
671
0 commit comments