]> git.lizzy.rs Git - rust.git/blob - src/libcore/internal_macros.rs
Don't default on std crate when manipulating browser history
[rust.git] / src / libcore / internal_macros.rs
1 // implements the unary operator "op &T"
2 // based on "op T" where T is expected to be `Copy`able
3 macro_rules! forward_ref_unop {
4     (impl $imp:ident, $method:ident for $t:ty) => {
5         forward_ref_unop!(impl $imp, $method for $t,
6                 #[stable(feature = "rust1", since = "1.0.0")]);
7     };
8     (impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
9         #[$attr]
10         impl<'a> $imp for &'a $t {
11             type Output = <$t as $imp>::Output;
12
13             #[inline]
14             fn $method(self) -> <$t as $imp>::Output {
15                 $imp::$method(*self)
16             }
17         }
18     }
19 }
20
21 // implements binary operators "&T op U", "T op &U", "&T op &U"
22 // based on "T op U" where T and U are expected to be `Copy`able
23 macro_rules! forward_ref_binop {
24     (impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
25         forward_ref_binop!(impl $imp, $method for $t, $u,
26                 #[stable(feature = "rust1", since = "1.0.0")]);
27     };
28     (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
29         #[$attr]
30         impl<'a> $imp<$u> for &'a $t {
31             type Output = <$t as $imp<$u>>::Output;
32
33             #[inline]
34             fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
35                 $imp::$method(*self, other)
36             }
37         }
38
39         #[$attr]
40         impl<'a> $imp<&'a $u> for $t {
41             type Output = <$t as $imp<$u>>::Output;
42
43             #[inline]
44             fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output {
45                 $imp::$method(self, *other)
46             }
47         }
48
49         #[$attr]
50         impl<'a, 'b> $imp<&'a $u> for &'b $t {
51             type Output = <$t as $imp<$u>>::Output;
52
53             #[inline]
54             fn $method(self, other: &'a $u) -> <$t as $imp<$u>>::Output {
55                 $imp::$method(*self, *other)
56             }
57         }
58     }
59 }
60
61 // implements "T op= &U", based on "T op= U"
62 // where U is expected to be `Copy`able
63 macro_rules! forward_ref_op_assign {
64     (impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
65         forward_ref_op_assign!(impl $imp, $method for $t, $u,
66                 #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
67     };
68     (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
69         #[$attr]
70         impl<'a> $imp<&'a $u> for $t {
71             #[inline]
72             fn $method(&mut self, other: &'a $u) {
73                 $imp::$method(self, *other);
74             }
75         }
76     }
77 }