@@ -230,7 +230,7 @@ pub trait FromSql {
230230 /// Creates a new value of this type from a buffer of Postgres data.
231231 ///
232232 /// 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 > > )
234234 -> Result < Self , PostgresError > ;
235235}
236236
@@ -257,17 +257,18 @@ impl RawFromSql for bool {
257257 }
258258}
259259
260- impl RawFromSql for ~ [ u8 ] {
260+ impl RawFromSql for Vec < u8 > {
261261 fn raw_from_sql < R : Reader > ( raw : & mut R )
262- -> Result < ~ [ u8 ] , PostgresError > {
262+ -> Result < Vec < u8 > , PostgresError > {
263263 Ok ( try_pg ! ( raw. read_to_end( ) ) )
264264 }
265265}
266266
267267impl RawFromSql for ~str {
268268 fn raw_from_sql < R : Reader > ( raw : & mut R )
269269 -> 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 ( ) )
271272 }
272273}
273274
@@ -297,7 +298,7 @@ impl RawFromSql for Timespec {
297298impl RawFromSql for Uuid {
298299 fn raw_from_sql < R : Reader > ( raw : & mut R )
299300 -> 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 ( ) )
301302 }
302303}
303304
@@ -363,7 +364,7 @@ impl RawFromSql for Json {
363364macro_rules! from_map_impl(
364365 ( $( $expected: pat) |+, $t: ty, $blk: expr) => (
365366 impl FromSql for Option <$t> {
366- fn from_sql( ty: & PostgresType , raw: & Option <~ [ u8 ] >)
367+ fn from_sql( ty: & PostgresType , raw: & Option <Vec < u8 > >)
367368 -> Result <Option <$t>, PostgresError > {
368369 check_types!( $( $expected) |+, ty)
369370 match * raw {
@@ -374,7 +375,7 @@ macro_rules! from_map_impl(
374375 }
375376
376377 impl FromSql for $t {
377- fn from_sql( ty: & PostgresType , raw: & Option <~ [ u8 ] >)
378+ fn from_sql( ty: & PostgresType , raw: & Option <Vec < u8 > >)
378379 -> Result <$t, PostgresError > {
379380 // FIXME when you can specify Self types properly
380381 let ret: Result <Option <$t>, PostgresError > = FromSql :: from_sql( ty, raw) ;
@@ -390,15 +391,15 @@ macro_rules! from_map_impl(
390391
391392macro_rules! from_raw_from_impl(
392393 ( $( $expected: pat) |+, $t: ty) => (
393- from_map_impl!( $( $expected) |+, $t, |buf: & ~ [ u8 ] | {
394+ from_map_impl!( $( $expected) |+, $t, |buf: & Vec < u8 > | {
394395 let mut reader = BufReader :: new( buf. as_slice( ) ) ;
395396 RawFromSql :: raw_from_sql( & mut reader)
396397 } )
397398 )
398399)
399400
400401from_raw_from_impl ! ( PgBool , bool )
401- from_raw_from_impl ! ( PgByteA , ~ [ u8 ] )
402+ from_raw_from_impl ! ( PgByteA , Vec < u8 > )
402403from_raw_from_impl ! ( PgVarchar | PgText | PgCharN , ~str )
403404from_raw_from_impl ! ( PgChar , i8 )
404405from_raw_from_impl ! ( PgInt2 , i16 )
@@ -416,7 +417,7 @@ from_raw_from_impl!(PgTsRange | PgTstzRange, Range<Timespec>)
416417
417418macro_rules! from_array_impl(
418419 ( $( $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 > | {
420421 let mut rdr = BufReader :: new( buf. as_slice( ) ) ;
421422
422423 let ndim = try_pg!( rdr. read_be_i32( ) ) as uint;
@@ -450,7 +451,7 @@ macro_rules! from_array_impl(
450451)
451452
452453from_array_impl ! ( PgBoolArray , bool )
453- from_array_impl ! ( PgByteAArray , ~ [ u8 ] )
454+ from_array_impl ! ( PgByteAArray , Vec < u8 > )
454455from_array_impl ! ( PgCharArray , i8 )
455456from_array_impl ! ( PgInt2Array , i16 )
456457from_array_impl ! ( PgInt4Array , i32 )
@@ -466,7 +467,7 @@ from_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
466467from_array_impl ! ( PgInt8RangeArray , Range <i64 >)
467468
468469impl 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 > > )
470471 -> Result < Option < HashMap < ~str , Option < ~str > > > , PostgresError > {
471472 match * ty {
472473 PgUnknownType { name : ref name, .. } if "hstore" == * name => { }
@@ -482,13 +483,15 @@ impl FromSql for Option<HashMap<~str, Option<~str>>> {
482483
483484 for _ in range ( 0 , count) {
484485 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 ( ) ;
486488
487489 let val_len = try_pg ! ( rdr. read_be_i32( ) ) ;
488490 let val = if val_len < 0 {
489491 None
490492 } 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 ( ) )
492495 } ;
493496
494497 map. insert ( key, val) ;
@@ -501,7 +504,7 @@ impl FromSql for Option<HashMap<~str, Option<~str>>> {
501504}
502505
503506impl 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 > > )
505508 -> Result < HashMap < ~str , Option < ~str > > , PostgresError > {
506509 // FIXME when you can specify Self types properly
507510 let ret: Result < Option < HashMap < ~str , Option < ~str > > > , PostgresError > = FromSql :: from_sql ( ty, raw) ;
@@ -518,7 +521,7 @@ pub trait ToSql {
518521 /// Converts the value of `self` into a format appropriate for the Postgres
519522 /// backend.
520523 fn to_sql ( & self , ty : & PostgresType )
521- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > ;
524+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > ;
522525}
523526
524527#[ doc( hidden) ]
@@ -543,12 +546,6 @@ impl RawToSql for bool {
543546 }
544547}
545548
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-
552549impl RawToSql for Vec < u8 > {
553550 fn raw_to_sql < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , PostgresError > {
554551 Ok ( try_pg ! ( w. write( self . as_slice( ) ) ) )
@@ -613,7 +610,7 @@ macro_rules! to_range_impl(
613610 try!( bound. value. raw_to_sql( & mut inner_buf) ) ;
614611 let inner_buf = inner_buf. unwrap( ) ;
615612 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 ( ) ) ) ;
617614 }
618615 None => { }
619616 }
@@ -623,7 +620,7 @@ macro_rules! to_range_impl(
623620 try!( bound. value. raw_to_sql( & mut inner_buf) ) ;
624621 let inner_buf = inner_buf. unwrap( ) ;
625622 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 ( ) ) ) ;
627624 }
628625 None => { }
629626 }
@@ -649,7 +646,7 @@ macro_rules! to_option_impl(
649646 ( $( $oid: pat) |+, $t: ty) => (
650647 impl ToSql for Option <$t> {
651648 fn to_sql( & self , ty: & PostgresType )
652- -> Result <( Format , Option <~ [ u8 ] >) , PostgresError > {
649+ -> Result <( Format , Option <Vec < u8 > >) , PostgresError > {
653650 check_types!( $( $oid) |+, ty)
654651
655652 match * self {
@@ -665,7 +662,7 @@ macro_rules! to_option_impl_lifetime(
665662 ( $( $oid: pat) |+, $t: ty) => (
666663 impl <' a> ToSql for Option <$t> {
667664 fn to_sql( & self , ty: & PostgresType )
668- -> Result <( Format , Option <~ [ u8 ] >) , PostgresError > {
665+ -> Result <( Format , Option <Vec < u8 > >) , PostgresError > {
669666 check_types!( $( $oid) |+, ty)
670667
671668 match * self {
@@ -681,7 +678,7 @@ macro_rules! to_raw_to_impl(
681678 ( $( $oid: ident) |+, $t: ty) => (
682679 impl ToSql for $t {
683680 fn to_sql( & self , ty: & PostgresType )
684- -> Result <( Format , Option <~ [ u8 ] >) , PostgresError > {
681+ -> Result <( Format , Option <Vec < u8 > >) , PostgresError > {
685682 check_types!( $( $oid) |+, ty)
686683
687684 let mut writer = MemWriter :: new( ) ;
@@ -695,7 +692,6 @@ macro_rules! to_raw_to_impl(
695692)
696693
697694to_raw_to_impl ! ( PgBool , bool )
698- to_raw_to_impl ! ( PgByteA , ~[ u8 ] )
699695to_raw_to_impl ! ( PgByteA , Vec <u8 >)
700696to_raw_to_impl ! ( PgVarchar | PgText | PgCharN , ~str )
701697to_raw_to_impl ! ( PgJson , Json )
@@ -711,19 +707,19 @@ to_raw_to_impl!(PgTsRange | PgTstzRange, Range<Timespec>)
711707
712708impl < ' a > ToSql for & ' a str {
713709 fn to_sql ( & self , ty : & PostgresType )
714- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > {
710+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > {
715711 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 ( ) ) ) ) )
717713 }
718714}
719715
720716to_option_impl_lifetime ! ( PgVarchar | PgText | PgCharN , & ' a str )
721717
722718impl < ' a > ToSql for & ' a [ u8 ] {
723719 fn to_sql ( & self , ty : & PostgresType )
724- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > {
720+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > {
725721 check_types ! ( PgByteA , ty)
726- Ok ( ( Binary , Some ( self . to_owned ( ) ) ) )
722+ Ok ( ( Binary , Some ( Vec :: from_slice ( * self ) ) ) )
727723 }
728724}
729725
@@ -736,7 +732,7 @@ macro_rules! to_array_impl(
736732 ( $( $oid: ident) |+, $t: ty) => (
737733 impl ToSql for ArrayBase <Option <$t>> {
738734 fn to_sql( & self , ty: & PostgresType )
739- -> Result <( Format , Option <~ [ u8 ] >) , PostgresError > {
735+ -> Result <( Format , Option <Vec < u8 > >) , PostgresError > {
740736 check_types!( $( $oid) |+, ty)
741737 let mut buf = MemWriter :: new( ) ;
742738
@@ -756,7 +752,7 @@ macro_rules! to_array_impl(
756752 try!( val. raw_to_sql( & mut inner_buf) ) ;
757753 let inner_buf = inner_buf. unwrap( ) ;
758754 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 ( ) ) ) ;
760756 }
761757 None => try_pg!( buf. write_be_i32( -1 ) )
762758 }
@@ -771,7 +767,6 @@ macro_rules! to_array_impl(
771767)
772768
773769to_array_impl ! ( PgBoolArray , bool )
774- to_array_impl ! ( PgByteAArray , ~[ u8 ] )
775770to_array_impl ! ( PgByteAArray , Vec <u8 >)
776771to_array_impl ! ( PgCharArray , i8 )
777772to_array_impl ! ( PgInt2Array , i16 )
@@ -789,7 +784,7 @@ to_array_impl!(PgJsonArray, Json)
789784
790785impl ToSql for HashMap < ~str , Option < ~str > > {
791786 fn to_sql ( & self , ty : & PostgresType )
792- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > {
787+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > {
793788 match * ty {
794789 PgUnknownType { name : ref name, .. } if "hstore" == * name => { }
795790 _ => return Err ( PgWrongType ( ty. clone ( ) ) )
@@ -818,7 +813,7 @@ impl ToSql for HashMap<~str, Option<~str>> {
818813
819814impl ToSql for Option < HashMap < ~str , Option < ~str > > > {
820815 fn to_sql ( & self , ty : & PostgresType )
821- -> Result < ( Format , Option < ~ [ u8 ] > ) , PostgresError > {
816+ -> Result < ( Format , Option < Vec < u8 > > ) , PostgresError > {
822817 match * ty {
823818 PgUnknownType { name : ref name, .. } if "hstore" == * name => { }
824819 _ => return Err ( PgWrongType ( ty. clone ( ) ) )
0 commit comments