mop_structs/
array.rs

1/// All supported (up to 32) Arrays implement this trait.
2pub trait Array {
3  const SIZE: usize;
4  /// Type
5  type Item;
6
7  /// Converts into a mutable slice.
8  fn as_mut_slice(&mut self) -> &mut [Self::Item];
9
10  /// Converts into a immutable slice.
11  fn as_slice(&self) -> &[Self::Item];
12}
13
14macro_rules! array_impls {
15    ($($N:expr),+) => {
16        $(
17            impl<T> Array for [T; $N] {
18                const SIZE: usize = $N;
19                type Item = T;
20
21                fn as_mut_slice(&mut self) -> &mut [T] {
22                    &mut self[..]
23                }
24
25                fn as_slice(&self) -> &[T] {
26                    &self[..]
27                }
28            }
29        )+
30    }
31}
32
33array_impls!(
34  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
35  27, 28, 29, 30, 31, 32, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
36  0x10000
37);