@@ -230,7 +230,7 @@ pub trait FromSql {
230
230
/// Creates a new value of this type from a buffer of Postgres data.
231
231
///
232
232
/// If the value was `NULL`, the buffer will be `None`.
233
- fn from_sql ( ty : & PostgresType , raw : & Option < ~ [ u8 ] > )
233
+ fn from_sql ( ty : & PostgresType , raw : & Option < Vec < u8 > > )
234
234
-> Result < Self , PostgresError > ;
235
235
}
236
236
@@ -257,17 +257,18 @@ impl RawFromSql for bool {
257
257
}
258
258
}
259
259
260
- impl RawFromSql for ~ [ u8 ] {
260
+ impl RawFromSql for Vec < u8 > {
261
261
fn raw_from_sql < R : Reader > ( raw : & mut R )
262
- -> Result < ~ [ u8 ] , PostgresError > {
262
+ -> Result < Vec < u8 > , PostgresError > {
263
263
Ok ( try_pg ! ( raw. read_to_end( ) ) )
264
264
}
265
265
}
266
266
267
267
impl RawFromSql for ~str {
268
268
fn raw_from_sql < R : Reader > ( raw : & mut R )
269
269
-> Result < ~str , PostgresError > {
270
- Ok ( str:: from_utf8_owned ( try_pg ! ( raw. read_to_end( ) ) ) . unwrap ( ) )
270
+ // FIXME
271
+ Ok ( str:: from_utf8 ( try_pg ! ( raw. read_to_end( ) ) . as_slice ( ) ) . unwrap ( ) . to_owned ( ) )
271
272
}
272
273
}
273
274
@@ -297,7 +298,7 @@ impl RawFromSql for Timespec {
297
298
impl RawFromSql for Uuid {
298
299
fn raw_from_sql < R : Reader > ( raw : & mut R )
299
300
-> Result < Uuid , PostgresError > {
300
- Ok ( Uuid :: from_bytes ( try_pg ! ( raw. read_to_end( ) ) ) . unwrap ( ) )
301
+ Ok ( Uuid :: from_bytes ( try_pg ! ( raw. read_to_end( ) ) . as_slice ( ) ) . unwrap ( ) )
301
302
}
302
303
}
303
304
@@ -363,7 +364,7 @@ impl RawFromSql for Json {
363
364
macro_rules! from_map_impl(
364
365
( $( $expected: pat) |+, $t: ty, $blk: expr) => (
365
366
impl FromSql for Option <$t> {
366
- fn from_sql( ty: & PostgresType , raw: & Option <~ [ u8 ] >)
367
+ fn from_sql( ty: & PostgresType , raw: & Option <Vec < u8 > >)
367
368
-> Result <Option <$t>, PostgresError > {
368
369
check_types!( $( $expected) |+, ty)
369
370
match * raw {
@@ -374,7 +375,7 @@ macro_rules! from_map_impl(
374
375
}
375
376
376
377
impl FromSql for $t {
377
- fn from_sql( ty: & PostgresType , raw: & Option <~ [ u8 ] >)
378
+ fn from_sql( ty: & PostgresType , raw: & Option <Vec < u8 > >)
378
379
-> Result <$t, PostgresError > {
379
380
// FIXME when you can specify Self types properly
380
381
let ret: Result <Option <$t>, PostgresError > = FromSql :: from_sql( ty, raw) ;
@@ -390,15 +391,15 @@ macro_rules! from_map_impl(
390
391
391
392
macro_rules! from_raw_from_impl(
392
393
( $( $expected: pat) |+, $t: ty) => (
393
- from_map_impl!( $( $expected) |+, $t, |buf: & ~ [ u8 ] | {
394
+ from_map_impl!( $( $expected) |+, $t, |buf: & Vec < u8 > | {
394
395
let mut reader = BufReader :: new( buf. as_slice( ) ) ;
395
396
RawFromSql :: raw_from_sql( & mut reader)
396
397
} )
397
398
)
398
399
)
399
400
400
401
from_raw_from_impl ! ( PgBool , bool )
401
- from_raw_from_impl ! ( PgByteA , ~ [ u8 ] )
402
+ from_raw_from_impl ! ( PgByteA , Vec < u8 > )
402
403
from_raw_from_impl ! ( PgVarchar | PgText | PgCharN , ~str )
403
404
from_raw_from_impl ! ( PgChar , i8 )
404
405
from_raw_from_impl ! ( PgInt2 , i16 )
@@ -416,7 +417,7 @@ from_raw_from_impl!(PgTsRange | PgTstzRange, Range<Timespec>)
416
417
417
418
macro_rules! from_array_impl(
418
419
( $( $oid: ident) |+, $t: ty) => (
419
- from_map_impl!( $( $oid) |+, ArrayBase <Option <$t>>, |buf: & ~ [ u8 ] | {
420
+ from_map_impl!( $( $oid) |+, ArrayBase <Option <$t>>, |buf: & Vec < u8 > | {
420
421
let mut rdr = BufReader :: new( buf. as_slice( ) ) ;
421
422
422
423
let ndim = try_pg!( rdr. read_be_i32( ) ) as uint;
@@ -450,7 +451,7 @@ macro_rules! from_array_impl(
450
451
)
451
452
452
453
from_array_impl ! ( PgBoolArray , bool )
453
- from_array_impl ! ( PgByteAArray , ~ [ u8 ] )
454
+ from_array_impl ! ( PgByteAArray , Vec < u8 > )
454
455
from_array_impl ! ( PgCharArray , i8 )
455
456
from_array_impl ! ( PgInt2Array , i16 )
456
457
from_array_impl ! ( PgInt4Array , i32 )
@@ -466,7 +467,7 @@ from_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
466
467
from_array_impl ! ( PgInt8RangeArray , Range <i64 >)
467
468
468
469
impl FromSql for Option < HashMap < ~str , Option < ~str > > > {
469
- fn from_sql ( ty : & PostgresType , raw : & Option < ~ [ u8 ] > )
470
+ fn from_sql ( ty : & PostgresType , raw : & Option < Vec < u8 > > )
470
471
-> Result < Option < HashMap < ~str , Option < ~str > > > , PostgresError > {
471
472
match * ty {
472
473
PgUnknownType { name : ref name, .. } if "hstore" == * name => { }
@@ -482,13 +483,15 @@ impl FromSql for Option<HashMap<~str, Option<~str>>> {
482
483
483
484
for _ in range ( 0 , count) {
484
485
let key_len = try_pg ! ( rdr. read_be_i32( ) ) ;
485
- let key = str:: from_utf8_owned ( try_pg ! ( rdr. read_exact( key_len as uint) ) ) . unwrap ( ) ;
486
+ let key = str:: from_utf8 ( try_pg ! ( rdr. read_exact( key_len as uint) ) . as_slice ( ) )
487
+ . unwrap ( ) . to_owned ( ) ;
486
488
487
489
let val_len = try_pg ! ( rdr. read_be_i32( ) ) ;
488
490
let val = if val_len < 0 {
489
491
None
490
492
} else {
491
- Some ( str:: from_utf8_owned ( try_pg ! ( rdr. read_exact( val_len as uint) ) ) . unwrap ( ) )
493
+ Some ( str:: from_utf8 ( try_pg ! ( rdr. read_exact( val_len as uint) ) . as_slice ( ) )
494
+ . unwrap ( ) . to_owned ( ) )
492
495
} ;
493
496
494
497
map. insert ( key, val) ;
@@ -501,7 +504,7 @@ impl FromSql for Option<HashMap<~str, Option<~str>>> {
501
504
}
502
505
503
506
impl FromSql for HashMap < ~str , Option < ~str > > {
504
- fn from_sql ( ty : & PostgresType , raw : & Option < ~ [ u8 ] > )
507
+ fn from_sql ( ty : & PostgresType , raw : & Option < Vec < u8 > > )
505
508
-> Result < HashMap < ~str , Option < ~str > > , PostgresError > {
506
509
// FIXME when you can specify Self types properly
507
510
let ret: Result < Option < HashMap < ~str , Option < ~str > > > , PostgresError > = FromSql :: from_sql ( ty, raw) ;
@@ -518,7 +521,7 @@ pub trait ToSql {
518
521
/// Converts the value of `self` into a format appropriate for the Postgres
519
522
/// backend.
520
523
fn to_sql ( & self , ty : & PostgresType )
521
- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > ;
524
+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > ;
522
525
}
523
526
524
527
#[ doc( hidden) ]
@@ -543,12 +546,6 @@ impl RawToSql for bool {
543
546
}
544
547
}
545
548
546
- impl RawToSql for ~[ u8 ] {
547
- fn raw_to_sql < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , PostgresError > {
548
- Ok ( try_pg ! ( w. write( self . as_slice( ) ) ) )
549
- }
550
- }
551
-
552
549
impl RawToSql for Vec < u8 > {
553
550
fn raw_to_sql < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , PostgresError > {
554
551
Ok ( try_pg ! ( w. write( self . as_slice( ) ) ) )
@@ -613,7 +610,7 @@ macro_rules! to_range_impl(
613
610
try!( bound. value. raw_to_sql( & mut inner_buf) ) ;
614
611
let inner_buf = inner_buf. unwrap( ) ;
615
612
try_pg!( buf. write_be_i32( inner_buf. len( ) as i32 ) ) ;
616
- try_pg!( buf. write( inner_buf) ) ;
613
+ try_pg!( buf. write( inner_buf. as_slice ( ) ) ) ;
617
614
}
618
615
None => { }
619
616
}
@@ -623,7 +620,7 @@ macro_rules! to_range_impl(
623
620
try!( bound. value. raw_to_sql( & mut inner_buf) ) ;
624
621
let inner_buf = inner_buf. unwrap( ) ;
625
622
try_pg!( buf. write_be_i32( inner_buf. len( ) as i32 ) ) ;
626
- try_pg!( buf. write( inner_buf) ) ;
623
+ try_pg!( buf. write( inner_buf. as_slice ( ) ) ) ;
627
624
}
628
625
None => { }
629
626
}
@@ -649,7 +646,7 @@ macro_rules! to_option_impl(
649
646
( $( $oid: pat) |+, $t: ty) => (
650
647
impl ToSql for Option <$t> {
651
648
fn to_sql( & self , ty: & PostgresType )
652
- -> Result <( Format , Option <~ [ u8 ] >) , PostgresError > {
649
+ -> Result <( Format , Option <Vec < u8 > >) , PostgresError > {
653
650
check_types!( $( $oid) |+, ty)
654
651
655
652
match * self {
@@ -665,7 +662,7 @@ macro_rules! to_option_impl_lifetime(
665
662
( $( $oid: pat) |+, $t: ty) => (
666
663
impl <' a> ToSql for Option <$t> {
667
664
fn to_sql( & self , ty: & PostgresType )
668
- -> Result <( Format , Option <~ [ u8 ] >) , PostgresError > {
665
+ -> Result <( Format , Option <Vec < u8 > >) , PostgresError > {
669
666
check_types!( $( $oid) |+, ty)
670
667
671
668
match * self {
@@ -681,7 +678,7 @@ macro_rules! to_raw_to_impl(
681
678
( $( $oid: ident) |+, $t: ty) => (
682
679
impl ToSql for $t {
683
680
fn to_sql( & self , ty: & PostgresType )
684
- -> Result <( Format , Option <~ [ u8 ] >) , PostgresError > {
681
+ -> Result <( Format , Option <Vec < u8 > >) , PostgresError > {
685
682
check_types!( $( $oid) |+, ty)
686
683
687
684
let mut writer = MemWriter :: new( ) ;
@@ -695,7 +692,6 @@ macro_rules! to_raw_to_impl(
695
692
)
696
693
697
694
to_raw_to_impl ! ( PgBool , bool )
698
- to_raw_to_impl ! ( PgByteA , ~[ u8 ] )
699
695
to_raw_to_impl ! ( PgByteA , Vec <u8 >)
700
696
to_raw_to_impl ! ( PgVarchar | PgText | PgCharN , ~str )
701
697
to_raw_to_impl ! ( PgJson , Json )
@@ -711,19 +707,19 @@ to_raw_to_impl!(PgTsRange | PgTstzRange, Range<Timespec>)
711
707
712
708
impl < ' a > ToSql for & ' a str {
713
709
fn to_sql ( & self , ty : & PostgresType )
714
- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > {
710
+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > {
715
711
check_types ! ( PgVarchar | PgText | PgCharN , ty)
716
- Ok ( ( Text , Some ( self . as_bytes ( ) . to_owned ( ) ) ) )
712
+ Ok ( ( Text , Some ( Vec :: from_slice ( self . as_bytes ( ) ) ) ) )
717
713
}
718
714
}
719
715
720
716
to_option_impl_lifetime ! ( PgVarchar | PgText | PgCharN , & ' a str )
721
717
722
718
impl < ' a > ToSql for & ' a [ u8 ] {
723
719
fn to_sql ( & self , ty : & PostgresType )
724
- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > {
720
+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > {
725
721
check_types ! ( PgByteA , ty)
726
- Ok ( ( Binary , Some ( self . to_owned ( ) ) ) )
722
+ Ok ( ( Binary , Some ( Vec :: from_slice ( * self ) ) ) )
727
723
}
728
724
}
729
725
@@ -736,7 +732,7 @@ macro_rules! to_array_impl(
736
732
( $( $oid: ident) |+, $t: ty) => (
737
733
impl ToSql for ArrayBase <Option <$t>> {
738
734
fn to_sql( & self , ty: & PostgresType )
739
- -> Result <( Format , Option <~ [ u8 ] >) , PostgresError > {
735
+ -> Result <( Format , Option <Vec < u8 > >) , PostgresError > {
740
736
check_types!( $( $oid) |+, ty)
741
737
let mut buf = MemWriter :: new( ) ;
742
738
@@ -756,7 +752,7 @@ macro_rules! to_array_impl(
756
752
try!( val. raw_to_sql( & mut inner_buf) ) ;
757
753
let inner_buf = inner_buf. unwrap( ) ;
758
754
try_pg!( buf. write_be_i32( inner_buf. len( ) as i32 ) ) ;
759
- try_pg!( buf. write( inner_buf) ) ;
755
+ try_pg!( buf. write( inner_buf. as_slice ( ) ) ) ;
760
756
}
761
757
None => try_pg!( buf. write_be_i32( -1 ) )
762
758
}
@@ -771,7 +767,6 @@ macro_rules! to_array_impl(
771
767
)
772
768
773
769
to_array_impl ! ( PgBoolArray , bool )
774
- to_array_impl ! ( PgByteAArray , ~[ u8 ] )
775
770
to_array_impl ! ( PgByteAArray , Vec <u8 >)
776
771
to_array_impl ! ( PgCharArray , i8 )
777
772
to_array_impl ! ( PgInt2Array , i16 )
@@ -789,7 +784,7 @@ to_array_impl!(PgJsonArray, Json)
789
784
790
785
impl ToSql for HashMap < ~str , Option < ~str > > {
791
786
fn to_sql ( & self , ty : & PostgresType )
792
- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > {
787
+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > {
793
788
match * ty {
794
789
PgUnknownType { name : ref name, .. } if "hstore" == * name => { }
795
790
_ => return Err ( PgWrongType ( ty. clone ( ) ) )
@@ -818,7 +813,7 @@ impl ToSql for HashMap<~str, Option<~str>> {
818
813
819
814
impl ToSql for Option < HashMap < ~str , Option < ~str > > > {
820
815
fn to_sql ( & self , ty : & PostgresType )
821
- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > {
816
+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > {
822
817
match * ty {
823
818
PgUnknownType { name : ref name, .. } if "hstore" == * name => { }
824
819
_ => return Err ( PgWrongType ( ty. clone ( ) ) )
0 commit comments