@@ -5,6 +5,7 @@ use crate::types::array_compatible;
55use crate :: types:: Type ;
66use crate :: { PgArgumentBuffer , PgHasArrayType , PgTypeInfo , PgValueRef , Postgres } ;
77use std:: borrow:: Cow ;
8+ use std:: sync:: Arc ;
89
910impl Type < Postgres > for str {
1011 fn type_info ( ) -> PgTypeInfo {
@@ -74,6 +75,16 @@ impl PgHasArrayType for String {
7475 }
7576}
7677
78+ impl PgHasArrayType for Arc < str > {
79+ fn array_type_info ( ) -> PgTypeInfo {
80+ <& str as PgHasArrayType >:: array_type_info ( )
81+ }
82+
83+ fn array_compatible ( ty : & PgTypeInfo ) -> bool {
84+ <& str as PgHasArrayType >:: array_compatible ( ty)
85+ }
86+ }
87+
7788impl Encode < ' _ , Postgres > for & ' _ str {
7889 fn encode_by_ref ( & self , buf : & mut PgArgumentBuffer ) -> Result < IsNull , BoxDynError > {
7990 buf. extend ( self . as_bytes ( ) ) ;
@@ -103,6 +114,12 @@ impl Encode<'_, Postgres> for String {
103114 }
104115}
105116
117+ impl Encode < ' _ , Postgres > for Arc < str > {
118+ fn encode_by_ref ( & self , buf : & mut PgArgumentBuffer ) -> Result < IsNull , BoxDynError > {
119+ <& str as Encode < Postgres > >:: encode ( & * * self , buf)
120+ }
121+ }
122+
106123impl < ' r > Decode < ' r , Postgres > for & ' r str {
107124 fn decode ( value : PgValueRef < ' r > ) -> Result < Self , BoxDynError > {
108125 value. as_str ( )
@@ -126,3 +143,9 @@ impl Decode<'_, Postgres> for String {
126143 Ok ( value. as_str ( ) ?. to_owned ( ) )
127144 }
128145}
146+
147+ impl Decode < ' _ , Postgres > for Arc < str > {
148+ fn decode ( value : PgValueRef < ' _ > ) -> Result < Self , BoxDynError > {
149+ Ok ( value. as_str ( ) ?. into ( ) )
150+ }
151+ }
0 commit comments