@@ -769,6 +769,40 @@ pub trait ToSql: fmt::Debug {
769
769
ty : & Type ,
770
770
out : & mut BytesMut ,
771
771
) -> Result < IsNull , Box < dyn Error + Sync + Send > > ;
772
+
773
+ /// Specify the encode format
774
+ fn encode_format ( & self ) -> i16 { 1 }
775
+
776
+ /// return string representation
777
+ fn as_string ( & self ) -> String {
778
+ panic ! ( "as_string not implemented for {:?}" , self )
779
+ }
780
+ }
781
+
782
+
783
+ /// A Wrapper type used for sending query parameters encoded as unknown.
784
+ #[ derive( Debug ) ]
785
+ pub struct Unknown < ' a > ( pub & ' a ( dyn ToSql + Sync ) ) ;
786
+
787
+ impl ToSql for Unknown < ' _ > {
788
+ fn to_sql (
789
+ & self ,
790
+ _ty : & Type ,
791
+ out : & mut BytesMut ,
792
+ ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
793
+ match * self {
794
+ Unknown ( val) => {
795
+ types:: text_to_sql ( & val. as_string ( ) , out) ;
796
+ Ok ( IsNull :: No )
797
+ }
798
+ }
799
+ }
800
+
801
+ fn accepts ( _ty : & Type ) -> bool { true }
802
+
803
+ fn encode_format ( & self ) -> i16 { 0 }
804
+
805
+ to_sql_checked ! ( ) ;
772
806
}
773
807
774
808
impl < ' a , T > ToSql for & ' a T
@@ -905,7 +939,7 @@ impl<'a> ToSql for &'a str {
905
939
_ => false ,
906
940
}
907
941
}
908
-
942
+ fn as_string ( & self ) -> String { self . to_string ( ) }
909
943
to_sql_checked ! ( ) ;
910
944
}
911
945
@@ -929,7 +963,7 @@ impl ToSql for String {
929
963
fn accepts ( ty : & Type ) -> bool {
930
964
<& str as ToSql >:: accepts ( ty)
931
965
}
932
-
966
+ fn as_string ( & self ) -> String { self . clone ( ) }
933
967
to_sql_checked ! ( ) ;
934
968
}
935
969
@@ -944,6 +978,10 @@ macro_rules! simple_to {
944
978
Ok ( IsNull :: No )
945
979
}
946
980
981
+ fn as_string( & self ) -> String {
982
+ format!( "{}" , & self )
983
+ }
984
+
947
985
accepts!( $( $expected) ,+) ;
948
986
949
987
to_sql_checked!( ) ;
0 commit comments