@@ -198,14 +198,6 @@ make_postgres_type!(
198198 INT8RANGEARRAYOID => PgInt8RangeArray member PgInt8Range
199199)
200200
201- /// The wire format of a Postgres value
202- pub enum Format {
203- /// A user-readable string format
204- Text = 0 ,
205- /// A machine-readable binary format
206- Binary = 1
207- }
208-
209201macro_rules! check_types(
210202 ( $( $expected: pat) |+, $actual: ident) => (
211203 match $actual {
@@ -497,10 +489,9 @@ impl FromSql for HashMap<String, Option<String>> {
497489
498490/// A trait for types that can be converted into Postgres values
499491pub trait ToSql {
500- /// Converts the value of `self` into a format appropriate for the Postgres
501- /// backend.
502- fn to_sql ( & self , ty : & PostgresType )
503- -> PostgresResult < ( Format , Option < Vec < u8 > > ) > ;
492+ /// Converts the value of `self` into the binary format appropriate for the
493+ /// Postgres backend.
494+ fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < Option < Vec < u8 > > > ;
504495}
505496
506497#[ doc( hidden) ]
@@ -612,11 +603,11 @@ impl RawToSql for Json {
612603macro_rules! to_option_impl(
613604 ( $( $oid: pat) |+, $t: ty) => (
614605 impl ToSql for Option <$t> {
615- fn to_sql( & self , ty: & PostgresType ) -> PostgresResult <( Format , Option <Vec <u8 >>) > {
606+ fn to_sql( & self , ty: & PostgresType ) -> PostgresResult <Option <Vec <u8 >>> {
616607 check_types!( $( $oid) |+, ty)
617608
618609 match * self {
619- None => Ok ( ( Text , None ) ) ,
610+ None => Ok ( None ) ,
620611 Some ( ref val) => val. to_sql( ty)
621612 }
622613 }
@@ -627,11 +618,11 @@ macro_rules! to_option_impl(
627618macro_rules! to_option_impl_lifetime(
628619 ( $( $oid: pat) |+, $t: ty) => (
629620 impl <' a> ToSql for Option <$t> {
630- fn to_sql( & self , ty: & PostgresType ) -> PostgresResult <( Format , Option <Vec <u8 >>) > {
621+ fn to_sql( & self , ty: & PostgresType ) -> PostgresResult <Option <Vec <u8 >>> {
631622 check_types!( $( $oid) |+, ty)
632623
633624 match * self {
634- None => Ok ( ( Text , None ) ) ,
625+ None => Ok ( None ) ,
635626 Some ( ref val) => val. to_sql( ty)
636627 }
637628 }
@@ -642,12 +633,12 @@ macro_rules! to_option_impl_lifetime(
642633macro_rules! to_raw_to_impl(
643634 ( $( $oid: ident) |+, $t: ty) => (
644635 impl ToSql for $t {
645- fn to_sql( & self , ty: & PostgresType ) -> PostgresResult <( Format , Option <Vec <u8 >>) > {
636+ fn to_sql( & self , ty: & PostgresType ) -> PostgresResult <Option <Vec <u8 >>> {
646637 check_types!( $( $oid) |+, ty)
647638
648639 let mut writer = MemWriter :: new( ) ;
649640 try!( self . raw_to_sql( & mut writer) ) ;
650- Ok ( ( Binary , Some ( writer. unwrap( ) ) ) )
641+ Ok ( Some ( writer. unwrap( ) ) )
651642 }
652643 }
653644
@@ -670,18 +661,18 @@ to_raw_to_impl!(PgInt8Range, Range<i64>)
670661to_raw_to_impl ! ( PgTsRange | PgTstzRange , Range <Timespec >)
671662
672663impl < ' a > ToSql for & ' a str {
673- fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < ( Format , Option < Vec < u8 > > ) > {
664+ fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < Option < Vec < u8 > > > {
674665 check_types ! ( PgVarchar | PgText | PgCharN | PgName , ty)
675- Ok ( ( Text , Some ( self . as_bytes ( ) . to_vec ( ) ) ) )
666+ Ok ( Some ( self . as_bytes ( ) . to_vec ( ) ) )
676667 }
677668}
678669
679670to_option_impl_lifetime ! ( PgVarchar | PgText | PgCharN | PgName , & ' a str )
680671
681672impl < ' a > ToSql for & ' a [ u8 ] {
682- fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < ( Format , Option < Vec < u8 > > ) > {
673+ fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < Option < Vec < u8 > > > {
683674 check_types ! ( PgByteA , ty)
684- Ok ( ( Binary , Some ( self . to_vec ( ) ) ) )
675+ Ok ( Some ( self . to_vec ( ) ) )
685676 }
686677}
687678
@@ -692,7 +683,7 @@ to_raw_to_impl!(PgTimestamp | PgTimestampTZ, Timespec)
692683macro_rules! to_array_impl(
693684 ( $( $oid: ident) |+, $t: ty) => (
694685 impl ToSql for ArrayBase <Option <$t>> {
695- fn to_sql( & self , ty: & PostgresType ) -> PostgresResult <( Format , Option <Vec <u8 >>) > {
686+ fn to_sql( & self , ty: & PostgresType ) -> PostgresResult <Option <Vec <u8 >>> {
696687 check_types!( $( $oid) |+, ty)
697688 let mut buf = MemWriter :: new( ) ;
698689
@@ -718,7 +709,7 @@ macro_rules! to_array_impl(
718709 }
719710 }
720711
721- Ok ( ( Binary , Some ( buf. unwrap( ) ) ) )
712+ Ok ( Some ( buf. unwrap( ) ) )
722713 }
723714 }
724715
@@ -742,7 +733,7 @@ to_array_impl!(PgInt8RangeArray, Range<i64>)
742733to_array_impl ! ( PgJsonArray , Json )
743734
744735impl ToSql for HashMap < String , Option < String > > {
745- fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < ( Format , Option < Vec < u8 > > ) > {
736+ fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < Option < Vec < u8 > > > {
746737 match * ty {
747738 PgUnknownType { name : ref name, .. } if "hstore" == name. as_slice ( ) => { }
748739 _ => return Err ( PgWrongType ( ty. clone ( ) ) )
@@ -765,20 +756,20 @@ impl ToSql for HashMap<String, Option<String>> {
765756 }
766757 }
767758
768- Ok ( ( Binary , Some ( buf. unwrap ( ) ) ) )
759+ Ok ( Some ( buf. unwrap ( ) ) )
769760 }
770761}
771762
772763impl ToSql for Option < HashMap < String , Option < String > > > {
773- fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < ( Format , Option < Vec < u8 > > ) > {
764+ fn to_sql ( & self , ty : & PostgresType ) -> PostgresResult < Option < Vec < u8 > > > {
774765 match * ty {
775766 PgUnknownType { name : ref name, .. } if "hstore" == name. as_slice ( ) => { }
776767 _ => return Err ( PgWrongType ( ty. clone ( ) ) )
777768 }
778769
779770 match * self {
780771 Some ( ref inner) => inner. to_sql ( ty) ,
781- None => Ok ( ( Binary , None ) )
772+ None => Ok ( None )
782773 }
783774 }
784775}
0 commit comments