| 34 |
34 |
| 35 impl<A, B> From<Pair<A, B>> for (A, B) { |
35 impl<A, B> From<Pair<A, B>> for (A, B) { |
| 36 #[inline] |
36 #[inline] |
| 37 fn from(Pair(a, b): Pair<A, B>) -> (A, B) { |
37 fn from(Pair(a, b): Pair<A, B>) -> (A, B) { |
| 38 (a, b) |
38 (a, b) |
| 39 } |
|
| 40 } |
|
| 41 |
|
| 42 macro_rules! impl_assignop { |
|
| 43 (($a : ty, $b : ty), $trait : ident, $fn : ident, $refr:ident) => { |
|
| 44 impl_assignop!(@doit: $a, $b, |
|
| 45 $trait, $fn; |
|
| 46 maybe_lifetime!($refr, &'r Pair<Ai,Bi>), |
|
| 47 (maybe_lifetime!($refr, &'r Ai), |
|
| 48 maybe_lifetime!($refr, &'r Bi)); |
|
| 49 $refr); |
|
| 50 }; |
|
| 51 (@doit: $a : ty, $b : ty, |
|
| 52 $trait:ident, $fn:ident; |
|
| 53 $in:ty, ($ain:ty, $bin:ty); |
|
| 54 $refr:ident) => { |
|
| 55 impl<'r, Ai, Bi> $trait<$in> |
|
| 56 for Pair<$a,$b> |
|
| 57 where $a: $trait<$ain>, |
|
| 58 $b: $trait<$bin> { |
|
| 59 #[inline] |
|
| 60 fn $fn(&mut self, y : $in) -> () { |
|
| 61 self.0.$fn(maybe_ref!($refr, y.0)); |
|
| 62 self.1.$fn(maybe_ref!($refr, y.1)); |
|
| 63 } |
|
| 64 } |
|
| 65 } |
39 } |
| 66 } |
40 } |
| 67 |
41 |
| 68 // macro_rules! impl_scalarop { |
42 // macro_rules! impl_scalarop { |
| 69 // (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => { |
43 // (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => { |
| 248 } |
222 } |
| 249 } |
223 } |
| 250 }; |
224 }; |
| 251 } |
225 } |
| 252 |
226 |
| |
227 macro_rules! impl_binary_mut { |
| |
228 ($trait:ident, $fn:ident) => { |
| |
229 impl<'a, A, B, C, D> $trait<Pair<C, D>> for Pair<A, B> |
| |
230 where |
| |
231 A: $trait<C>, |
| |
232 B: $trait<D>, |
| |
233 { |
| |
234 fn $fn(&mut self, Pair(c, d): Pair<C, D>) { |
| |
235 let Pair(ref mut a, ref mut b) = self; |
| |
236 a.$fn(c); |
| |
237 b.$fn(d); |
| |
238 } |
| |
239 } |
| |
240 |
| |
241 impl<'a, 'b, A, B, C, D> $trait<&'b Pair<C, D>> for Pair<A, B> |
| |
242 where |
| |
243 A: $trait<&'b C>, |
| |
244 B: $trait<&'b D>, |
| |
245 { |
| |
246 fn $fn(&mut self, Pair(ref c, ref d): &'b Pair<C, D>) { |
| |
247 let Pair(ref mut a, ref mut b) = self; |
| |
248 a.$fn(c); |
| |
249 b.$fn(d); |
| |
250 } |
| |
251 } |
| |
252 }; |
| |
253 } |
| |
254 |
| 253 impl_binary!(Add, add); |
255 impl_binary!(Add, add); |
| 254 impl_binary!(Sub, sub); |
256 impl_binary!(Sub, sub); |
| |
257 impl_binary_mut!(AddAssign, add_assign); |
| |
258 impl_binary_mut!(SubAssign, sub_assign); |
| 255 |
259 |
| 256 #[macro_export] |
260 #[macro_export] |
| 257 macro_rules! impl_pair_vectorspace_ops { |
261 macro_rules! impl_pair_vectorspace_ops { |
| 258 (($a:ty, $b:ty), $field:ty) => { |
262 (($a:ty, $b:ty), $field:ty) => { |
| 259 //impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); |
263 //impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); |
| 260 //impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub); |
264 //impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub); |
| 261 impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign); |
265 //impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign); |
| 262 impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign); |
266 //impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign); |
| 263 // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul); |
267 // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul); |
| 264 // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div); |
268 // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div); |
| 265 // Compiler overflow |
269 // Compiler overflow |
| 266 // $( |
270 // $( |
| 267 // impl_pair_vectorspace_ops!(@scalar_lhs, ($a, $b), $field, $impl_scalarlhs_op, Mul, mul); |
271 // impl_pair_vectorspace_ops!(@scalar_lhs, ($a, $b), $field, $impl_scalarlhs_op, Mul, mul); |
| 272 (@binary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { |
276 (@binary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { |
| 273 impl_binop!(($a, $b), $trait, $fn, ref, ref); |
277 impl_binop!(($a, $b), $trait, $fn, ref, ref); |
| 274 impl_binop!(($a, $b), $trait, $fn, ref, noref); |
278 impl_binop!(($a, $b), $trait, $fn, ref, noref); |
| 275 impl_binop!(($a, $b), $trait, $fn, noref, ref); |
279 impl_binop!(($a, $b), $trait, $fn, noref, ref); |
| 276 impl_binop!(($a, $b), $trait, $fn, noref, noref); |
280 impl_binop!(($a, $b), $trait, $fn, noref, noref); |
| 277 }; |
|
| 278 (@assign, ($a : ty, $b : ty), $trait : ident, $fn :ident) => { |
|
| 279 impl_assignop!(($a, $b), $trait, $fn, ref); |
|
| 280 impl_assignop!(($a, $b), $trait, $fn, noref); |
|
| 281 }; |
281 }; |
| 282 (@scalar, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn :ident) => { |
282 (@scalar, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn :ident) => { |
| 283 impl_scalarop!(($a, $b), $field, $trait, $fn, ref); |
283 impl_scalarop!(($a, $b), $field, $trait, $fn, ref); |
| 284 impl_scalarop!(($a, $b), $field, $trait, $fn, noref); |
284 impl_scalarop!(($a, $b), $field, $trait, $fn, noref); |
| 285 }; |
285 }; |