]> git.lizzy.rs Git - rust.git/blob - src/libcore/array.rs
Add verbose option to rustdoc in order to fix problem with --version
[rust.git] / src / libcore / array.rs
1 // Copyright 2014 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 //! Implementations of things like `Eq` for fixed-length arrays
12 //! up to a certain length. Eventually we should able to generalize
13 //! to all lengths.
14
15 #![experimental] // not yet reviewed
16
17 use clone::Clone;
18 use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
19 use fmt;
20 use kinds::Copy;
21 use ops::Deref;
22 use option::Option;
23
24 // macro for implementing n-ary tuple functions and operations
25 macro_rules! array_impls {
26     ($($N:expr)+) => {
27         $(
28             #[stable]
29             impl<T:Copy> Clone for [T, ..$N] {
30                 fn clone(&self) -> [T, ..$N] {
31                     *self
32                 }
33             }
34
35             #[unstable = "waiting for Show to stabilize"]
36             impl<T:fmt::Show> fmt::Show for [T, ..$N] {
37                 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38                     fmt::Show::fmt(&self[], f)
39                 }
40             }
41
42             #[unstable = "waiting for PartialEq to stabilize"]
43             impl<A, B> PartialEq<[B, ..$N]> for [A, ..$N] where A: PartialEq<B> {
44                 #[inline]
45                 fn eq(&self, other: &[B, ..$N]) -> bool {
46                     self[] == other[]
47                 }
48                 #[inline]
49                 fn ne(&self, other: &[B, ..$N]) -> bool {
50                     self[] != other[]
51                 }
52             }
53
54             impl<'a, A, B, Rhs> PartialEq<Rhs> for [A, ..$N] where
55                 A: PartialEq<B>,
56                 Rhs: Deref<[B]>,
57             {
58                 #[inline(always)]
59                 fn eq(&self, other: &Rhs) -> bool { PartialEq::eq(self[], &**other) }
60                 #[inline(always)]
61                 fn ne(&self, other: &Rhs) -> bool { PartialEq::ne(self[], &**other) }
62             }
63
64             impl<'a, A, B, Lhs> PartialEq<[B, ..$N]> for Lhs where
65                 A: PartialEq<B>,
66                 Lhs: Deref<[A]>
67             {
68                 #[inline(always)]
69                 fn eq(&self, other: &[B, ..$N]) -> bool { PartialEq::eq(&**self, other[]) }
70                 #[inline(always)]
71                 fn ne(&self, other: &[B, ..$N]) -> bool { PartialEq::ne(&**self, other[]) }
72             }
73
74             #[unstable = "waiting for Eq to stabilize"]
75             impl<T:Eq> Eq for [T, ..$N] { }
76
77             #[unstable = "waiting for PartialOrd to stabilize"]
78             impl<T:PartialOrd> PartialOrd for [T, ..$N] {
79                 #[inline]
80                 fn partial_cmp(&self, other: &[T, ..$N]) -> Option<Ordering> {
81                     PartialOrd::partial_cmp(&self[], &other[])
82                 }
83                 #[inline]
84                 fn lt(&self, other: &[T, ..$N]) -> bool {
85                     PartialOrd::lt(&self[], &other[])
86                 }
87                 #[inline]
88                 fn le(&self, other: &[T, ..$N]) -> bool {
89                     PartialOrd::le(&self[], &other[])
90                 }
91                 #[inline]
92                 fn ge(&self, other: &[T, ..$N]) -> bool {
93                     PartialOrd::ge(&self[], &other[])
94                 }
95                 #[inline]
96                 fn gt(&self, other: &[T, ..$N]) -> bool {
97                     PartialOrd::gt(&self[], &other[])
98                 }
99             }
100
101             #[unstable = "waiting for Ord to stabilize"]
102             impl<T:Ord> Ord for [T, ..$N] {
103                 #[inline]
104                 fn cmp(&self, other: &[T, ..$N]) -> Ordering {
105                     Ord::cmp(&self[], &other[])
106                 }
107             }
108         )+
109     }
110 }
111
112 array_impls! {
113      0  1  2  3  4  5  6  7  8  9
114     10 11 12 13 14 15 16 17 18 19
115     20 21 22 23 24 25 26 27 28 29
116     30 31 32
117 }