]> git.lizzy.rs Git - rust.git/blob - src/libcore/internal_macros.rs
f2cdc9d6a98c540de1c55271509687c2f0a89b71
[rust.git] / src / libcore / internal_macros.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 // implements the unary operator "op &T"
13 // based on "op T" where T is expected to be `Copy`able
14 macro_rules! forward_ref_unop {
15     (impl $imp:ident, $method:ident for $t:ty) => {
16         #[stable(feature = "rust1", since = "1.0.0")]
17         impl<'a> $imp for &'a $t {
18             type Output = <$t as $imp>::Output;
19
20             #[inline]
21             fn $method(self) -> <$t as $imp>::Output {
22                 $imp::$method(*self)
23             }
24         }
25     }
26 }
27
28 // implements binary operators "&T op U", "T op &U", "&T op &U"
29 // based on "T op U" where T and U are expected to be `Copy`able
30 macro_rules! forward_ref_binop {
31     (impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
32         #[stable(feature = "rust1", since = "1.0.0")]
33         impl<'a> $imp<$u> for &'a $t {
34             type Output = <$t as $imp<$u>>::Output;
35
36             #[inline]
37             fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
38                 $imp::$method(*self, other)
39             }
40         }
41
42         #[stable(feature = "rust1", since = "1.0.0")]
43         impl<'a> $imp<&'a $u> for $t {
44             type Output = <$t as $imp<$u>>::Output;
45
46             #[inline]
47             fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output {
48                 $imp::$method(self, *other)
49             }
50         }
51
52         #[stable(feature = "rust1", since = "1.0.0")]
53         impl<'a, 'b> $imp<&'a $u> for &'b $t {
54             type Output = <$t as $imp<$u>>::Output;
55
56             #[inline]
57             fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output {
58                 $imp::$method(*self, *other)
59             }
60         }
61     }
62 }