@@ -133,34 +133,45 @@ macro_rules! impl_encode_for_option {
133133 } ;
134134}
135135
136- impl < ' q , T , DB : Database > Encode < ' q , DB > for Arc < T >
137- where
138- T : Encode < ' q , DB > ,
139- {
140- #[ inline]
141- fn encode ( self , buf : & mut <DB as Database >:: ArgumentBuffer < ' q > ) -> Result < IsNull , BoxDynError > {
142- <T as Encode < DB > >:: encode_by_ref ( self . as_ref ( ) , buf)
143- }
136+ macro_rules! impl_encode_for_smartpointer {
137+ ( $smart_pointer: ty) => {
138+ impl <' q, T , DB : Database > Encode <' q, DB > for $smart_pointer
139+ where
140+ T : Encode <' q, DB >,
141+ {
142+ #[ inline]
143+ fn encode(
144+ self ,
145+ buf: & mut <DB as Database >:: ArgumentBuffer <' q>,
146+ ) -> Result <IsNull , BoxDynError > {
147+ <T as Encode <DB >>:: encode_by_ref( self . as_ref( ) , buf)
148+ }
144149
145- #[ inline]
146- fn encode_by_ref (
147- & self ,
148- buf : & mut <DB as Database >:: ArgumentBuffer < ' q > ,
149- ) -> Result < IsNull , BoxDynError > {
150- <& T as Encode < DB > >:: encode ( self , buf)
151- }
150+ #[ inline]
151+ fn encode_by_ref(
152+ & self ,
153+ buf: & mut <DB as Database >:: ArgumentBuffer <' q>,
154+ ) -> Result <IsNull , BoxDynError > {
155+ <& T as Encode <DB >>:: encode( self , buf)
156+ }
152157
153- #[ inline]
154- fn produces ( & self ) -> Option < DB :: TypeInfo > {
155- ( * * self ) . produces ( )
156- }
158+ #[ inline]
159+ fn produces( & self ) -> Option <DB :: TypeInfo > {
160+ ( * * self ) . produces( )
161+ }
157162
158- #[ inline]
159- fn size_hint ( & self ) -> usize {
160- ( * * self ) . size_hint ( )
161- }
163+ #[ inline]
164+ fn size_hint( & self ) -> usize {
165+ ( * * self ) . size_hint( )
166+ }
167+ }
168+ } ;
162169}
163170
171+ impl_encode_for_smartpointer ! ( Arc <T >) ;
172+ impl_encode_for_smartpointer ! ( Box <T >) ;
173+ impl_encode_for_smartpointer ! ( Rc <T >) ;
174+
164175impl < ' q , T , DB : Database > Encode < ' q , DB > for Cow < ' _ , T >
165176where
166177 T : Encode < ' q , DB > ,
@@ -189,59 +200,3 @@ where
189200 ( * * self ) . size_hint ( )
190201 }
191202}
192-
193- impl < ' q , T , DB : Database > Encode < ' q , DB > for Box < T >
194- where
195- T : Encode < ' q , DB > ,
196- {
197- #[ inline]
198- fn encode ( self , buf : & mut <DB as Database >:: ArgumentBuffer < ' q > ) -> Result < IsNull , BoxDynError > {
199- <T as Encode < DB > >:: encode_by_ref ( self . as_ref ( ) , buf)
200- }
201-
202- #[ inline]
203- fn encode_by_ref (
204- & self ,
205- buf : & mut <DB as Database >:: ArgumentBuffer < ' q > ,
206- ) -> Result < IsNull , BoxDynError > {
207- <& T as Encode < DB > >:: encode ( self , buf)
208- }
209-
210- #[ inline]
211- fn produces ( & self ) -> Option < DB :: TypeInfo > {
212- ( * * self ) . produces ( )
213- }
214-
215- #[ inline]
216- fn size_hint ( & self ) -> usize {
217- ( * * self ) . size_hint ( )
218- }
219- }
220-
221- impl < ' q , T , DB : Database > Encode < ' q , DB > for Rc < T >
222- where
223- T : Encode < ' q , DB > ,
224- {
225- #[ inline]
226- fn encode ( self , buf : & mut <DB as Database >:: ArgumentBuffer < ' q > ) -> Result < IsNull , BoxDynError > {
227- <T as Encode < DB > >:: encode_by_ref ( self . as_ref ( ) , buf)
228- }
229-
230- #[ inline]
231- fn encode_by_ref (
232- & self ,
233- buf : & mut <DB as Database >:: ArgumentBuffer < ' q > ,
234- ) -> Result < IsNull , BoxDynError > {
235- <& T as Encode < DB > >:: encode ( self , buf)
236- }
237-
238- #[ inline]
239- fn produces ( & self ) -> Option < DB :: TypeInfo > {
240- ( * * self ) . produces ( )
241- }
242-
243- #[ inline]
244- fn size_hint ( & self ) -> usize {
245- ( * * self ) . size_hint ( )
246- }
247- }
0 commit comments