@@ -155,6 +155,7 @@ pub use pg_lsn::PgLsn;
155
155
156
156
pub use crate :: special:: { Date , Timestamp } ;
157
157
use bytes:: BytesMut ;
158
+ use smol_str:: SmolStr ;
158
159
159
160
// Number of seconds from 1970-01-01 to 2000-01-01
160
161
const TIME_SEC_CONVERSION : u64 = 946_684_800 ;
@@ -629,6 +630,18 @@ impl<'a> FromSql<'a> for Box<str> {
629
630
}
630
631
}
631
632
633
+ #[ cfg( feature = "smol_str" ) ]
634
+ impl < ' a > FromSql < ' a > for smol_str:: SmolStr {
635
+ fn from_sql ( ty : & Type , raw : & ' a [ u8 ] ) -> Result < SmolStr , Box < dyn Error + Sync + Send > > {
636
+ <& str as FromSql >:: from_sql ( ty, raw)
637
+ . map ( SmolStr :: from)
638
+ }
639
+
640
+ fn accepts ( ty : & Type ) -> bool {
641
+ <& str as FromSql >:: accepts ( ty)
642
+ }
643
+ }
644
+
632
645
impl < ' a > FromSql < ' a > for & ' a str {
633
646
fn from_sql ( ty : & Type , raw : & ' a [ u8 ] ) -> Result < & ' a str , Box < dyn Error + Sync + Send > > {
634
647
match * ty {
@@ -1029,6 +1042,19 @@ impl ToSql for Box<str> {
1029
1042
to_sql_checked ! ( ) ;
1030
1043
}
1031
1044
1045
+ #[ cfg( feature = "smol_str" ) ]
1046
+ impl ToSql for smol_str:: SmolStr {
1047
+ fn to_sql ( & self , ty : & Type , w : & mut BytesMut ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
1048
+ <& str as ToSql >:: to_sql ( & & * * self , ty, w)
1049
+ }
1050
+
1051
+ fn accepts ( ty : & Type ) -> bool {
1052
+ <& str as ToSql >:: accepts ( ty)
1053
+ }
1054
+
1055
+ to_sql_checked ! ( ) ;
1056
+ }
1057
+
1032
1058
macro_rules! simple_to {
1033
1059
( $t: ty, $f: ident, $( $expected: ident) ,+) => {
1034
1060
impl ToSql for $t {
0 commit comments