1pub trait ArrayLike<T> : Eq + Clone + AsRef<[T]> {
8 type Pred;
9 type Succ;
10
11 fn remove_val(&self, i: usize) -> <Self as ArrayLike<T>>::Pred;
12
13 fn ndims(&self) -> usize {
14 self.as_ref().len()
15 }
16}
17
18pub trait ArrayLikeMut<T> : ArrayLike<T> + AsMut<[T]> {}
19
20macro_rules! array_impl {
21 ($len:expr) => (
22 impl<T: Copy + Eq> ArrayLike<T> for [T; $len] {
23 type Pred = [T; $len - 1];
24 type Succ = [T; $len + 1];
25
26 fn remove_val(&self, i: usize) -> <Self as ArrayLike<T>>::Pred {
27 let mut res = [self[i]; $len - 1];
28 for (count, &val) in self.as_ref()[0..i].iter().enumerate() {
29 res[count] = val;
30 }
31 for (count, &val) in self.as_ref()[(i+1)..].iter().enumerate() {
32 res[i + count] = val;
33 }
34 res
35 }
36 }
37 impl<T: Copy + Eq> ArrayLikeMut<T> for [T; $len] {}
38
39 )
40}
41
42impl<T: Copy + Eq> ArrayLike<T> for [T; 0] {
44 type Pred = [T; 0]; type Succ = [T; 1];
46 fn remove_val(&self, _: usize) -> <Self as ArrayLike<T>>::Pred {
47 self.clone()
48 }
49}
50impl<T: Copy + Eq> ArrayLikeMut<T> for [T; 0] {}
51
52array_impl!(1);
53array_impl!(2);
54array_impl!(3);
55array_impl!(4);
56array_impl!(5);
57array_impl!(6);
58array_impl!(7);
59array_impl!(8);
60array_impl!(9);
61array_impl!(10);
62array_impl!(11);
63array_impl!(12);
64array_impl!(13);
65array_impl!(14);
66array_impl!(15);
67array_impl!(16);
68array_impl!(17);
69array_impl!(18);
70array_impl!(19);
71array_impl!(20);
72array_impl!(21);
73array_impl!(22);
74array_impl!(23);
75array_impl!(24);
76array_impl!(25);
77array_impl!(26);
78array_impl!(27);
79array_impl!(28);
80array_impl!(29);
81array_impl!(30);
82array_impl!(31);
83array_impl!(32);
84