@@ -133,34 +133,45 @@ macro_rules! impl_encode_for_option {
133
133
} ;
134
134
}
135
135
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
+ }
144
149
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
+ }
152
157
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
+ }
157
162
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
+ } ;
162
169
}
163
170
171
+ impl_encode_for_smartpointer ! ( Arc <T >) ;
172
+ impl_encode_for_smartpointer ! ( Box <T >) ;
173
+ impl_encode_for_smartpointer ! ( Rc <T >) ;
174
+
164
175
impl < ' q , T , DB : Database > Encode < ' q , DB > for Cow < ' _ , T >
165
176
where
166
177
T : Encode < ' q , DB > ,
@@ -189,59 +200,3 @@ where
189
200
( * * self ) . size_hint ( )
190
201
}
191
202
}
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