@@ -209,16 +209,14 @@ macro_rules! result_body {
209
209
paste:: paste! {
210
210
let mut result = $self;
211
211
result. [ <$name _assign>] ( & $( $deref) ?$other) ;
212
- result
212
+ return result;
213
213
}
214
214
}
215
215
}
216
216
217
217
macro_rules! assign_body {
218
218
( $name: ident, $self: ident, $other: ident, $( $deref: tt) ?) => {
219
- paste:: paste! {
220
- $self. [ <$name _assign>] ( & $( $deref) ?$other) ;
221
- }
219
+ $self. $name( & $( $deref) ?$other)
222
220
}
223
221
}
224
222
@@ -237,7 +235,8 @@ macro_rules! impl_ops_from_ref {
237
235
(
238
236
$name: ident,
239
237
$body: ident
240
- $d( , { $d output: ident} ) ?
238
+ $d( , { $d output: ident $d ReturnType : ident} ) ?
239
+ $d( , [ $d self_mut: tt] ) ?
241
240
$d( , <$d lifetime: tt $d mut : tt $d deref: tt>) ?
242
241
) => {
243
242
paste:: paste! {
@@ -249,19 +248,35 @@ macro_rules! impl_ops_from_ref {
249
248
$type_params:
250
249
$bounds$( <$( $bound_params) * >) ?
251
250
) ,*
252
- > [ <$name: camel>] <$d( & $d lifetime ) ?$d ( $d mut ) ?Self > for $type<$( $type_params) ,* >
251
+ > [ <$name: camel>] <$d( & $d lifetime $d mut ) ?Self > for $type<$( $type_params) ,* >
253
252
{
254
253
$d( type $d output = Self ; ) ?
255
254
256
255
#[ inline]
257
- fn $name( self , other: Self ) -> Self {
256
+ fn $name(
257
+ $d( & $d self_mut) ?self ,
258
+ other: $d( & $d lifetime ) ?$d( $d mut ) ?Self
259
+ ) $d( -> $d ReturnType ) ? {
258
260
$body!( $name, self , other, $d( $d deref) ?) ;
259
261
}
260
262
}
261
263
}
262
264
}
263
265
}
264
266
267
+ macro_rules! instantiate_ops {
268
+ ( $d( $d op: ident) , * ) => {
269
+ paste:: paste! {
270
+ $d(
271
+ ops!( $d op, result_body, { Output Self } ) ;
272
+ ops!( $d op, result_body, { Output Self } , <' a mut * >) ;
273
+ ops!( [ <$d op _assign>] , assign_body, [ mut ] ) ;
274
+ ops!( [ <$d op _assign>] , assign_body, [ mut ] , <' a mut * >) ;
275
+ ) *
276
+ }
277
+ }
278
+ }
279
+
265
280
macro_rules! iter {
266
281
(
267
282
$name: ident,
@@ -291,26 +306,7 @@ macro_rules! impl_ops_from_ref {
291
306
}
292
307
293
308
instantiate!( $) ;
294
-
295
- ops!( add, result_body, { Output } ) ;
296
- ops!( add, result_body, { Output } , <' a mut * >) ;
297
- ops!( sub, result_body, { Output } ) ;
298
- ops!( sub, result_body, { Output } , <' a mut * >) ;
299
-
300
- ops!( mul, result_body, { Output } ) ;
301
- ops!( mul, result_body, { Output } , <' a mut * >) ;
302
- ops!( div, result_body, { Output } ) ;
303
- ops!( div, result_body, { Output } , <' a mut * >) ;
304
-
305
- ops!( add_assign, assign_body) ;
306
- ops!( add_assign, assign_body, <' a mut * >) ;
307
- ops!( sub_assign, assign_body) ;
308
- ops!( sub_assign, assign_body, <' a mut * >) ;
309
-
310
- ops!( mul_assign, assign_body) ;
311
- ops!( mul_assign, assign_body, <' a mut * >) ;
312
- ops!( div_assign, assign_body) ;
313
- ops!( div_assign, assign_body, <' a mut * >) ;
309
+ instantiate_ops!( add, sub, mul, div) ;
314
310
315
311
use core:: iter:: { Sum , Product } ;
316
312
0 commit comments