@@ -155,6 +155,7 @@ pub use pg_lsn::PgLsn;
155155
156156pub use crate :: special:: { Date , Timestamp } ;
157157use bytes:: BytesMut ;
158+ use smol_str:: SmolStr ;
158159
159160// Number of seconds from 1970-01-01 to 2000-01-01
160161const TIME_SEC_CONVERSION : u64 = 946_684_800 ;
@@ -629,6 +630,18 @@ impl<'a> FromSql<'a> for Box<str> {
629630 }
630631}
631632
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+
632645impl < ' a > FromSql < ' a > for & ' a str {
633646 fn from_sql ( ty : & Type , raw : & ' a [ u8 ] ) -> Result < & ' a str , Box < dyn Error + Sync + Send > > {
634647 match * ty {
@@ -1029,6 +1042,19 @@ impl ToSql for Box<str> {
10291042 to_sql_checked ! ( ) ;
10301043}
10311044
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+
10321058macro_rules! simple_to {
10331059 ( $t: ty, $f: ident, $( $expected: ident) ,+) => {
10341060 impl ToSql for $t {
0 commit comments