]> git.lizzy.rs Git - rust.git/blob - src/libcore/cmp_macros.rs
Auto merge of #29454 - stepancheg:vec-reserve, r=bluss
[rust.git] / src / libcore / cmp_macros.rs
1 // Copyright 2015 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 // Utility macros for implementing PartialEq on slice-like types
12
13 #![doc(hidden)]
14
15 #[macro_export]
16 macro_rules! __impl_slice_eq1 {
17     ($Lhs: ty, $Rhs: ty) => {
18         __impl_slice_eq1! { $Lhs, $Rhs, Sized }
19     };
20     ($Lhs: ty, $Rhs: ty, $Bound: ident) => {
21         #[stable(feature = "rust1", since = "1.0.0")]
22         impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> {
23             #[inline]
24             fn eq(&self, other: &$Rhs) -> bool { self[..] == other[..] }
25             #[inline]
26             fn ne(&self, other: &$Rhs) -> bool { self[..] != other[..] }
27         }
28     }
29 }
30
31 #[macro_export]
32 macro_rules! __impl_slice_eq2 {
33     ($Lhs: ty, $Rhs: ty) => {
34         __impl_slice_eq2! { $Lhs, $Rhs, Sized }
35     };
36     ($Lhs: ty, $Rhs: ty, $Bound: ident) => {
37         __impl_slice_eq1!($Lhs, $Rhs, $Bound);
38
39         #[stable(feature = "rust1", since = "1.0.0")]
40         impl<'a, 'b, A: $Bound, B> PartialEq<$Lhs> for $Rhs where B: PartialEq<A> {
41             #[inline]
42             fn eq(&self, other: &$Lhs) -> bool { self[..] == other[..] }
43             #[inline]
44             fn ne(&self, other: &$Lhs) -> bool { self[..] != other[..] }
45         }
46     }
47 }