Skip to main content

libutils_array/
index.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> SUPER
6use super::Array;
7
8//> HEAD -> CORE
9use core::ops::{
10    Index,
11    IndexMut,
12    Range,
13    RangeFrom,
14    RangeFull,
15    RangeInclusive,
16    RangeTo,
17    RangeToInclusive
18};
19
20
21//^
22//^ USIZE
23//^
24
25//> USIZE -> IMPLEMENTATION
26const impl<Type, const N: usize> Index<usize> for Array<Type, N> {
27    type Output = Type;
28    fn index(&self, index: usize) -> &Self::Output {self.get(index).unwrap()}
29}
30
31//> USIZE -> MUT IMPLEMENTATION
32const impl<Type, const N: usize> IndexMut<usize> for Array<Type, N> {
33    fn index_mut(&mut self, index: usize) -> &mut Self::Output {self.get_mut(index).unwrap()}
34}
35
36
37//^
38//^ RANGE
39//^
40
41//> RANGE -> IMPLEMENTATION
42const impl<Type, const N: usize> Index<Range<usize>> for Array<Type, N> {
43    type Output = [Type];
44    fn index(&self, index: Range<usize>) -> &Self::Output {self.as_ref().index(index)}
45}
46
47//> RANGE -> MUT IMPLEMENTATION
48const impl<Type, const N: usize> IndexMut<Range<usize>> for Array<Type, N> {
49    fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
50}
51
52
53//^
54//^ RANGEFROM
55//^
56
57//> RANGEFROM -> IMPLEMENTATION
58const impl<Type, const N: usize> Index<RangeFrom<usize>> for Array<Type, N> {
59    type Output = [Type];
60    fn index(&self, index: RangeFrom<usize>) -> &Self::Output {self.as_ref().index(index)}
61}
62
63//> RANGEFROM -> MUT IMPLEMENTATION
64const impl<Type, const N: usize> IndexMut<RangeFrom<usize>> for Array<Type, N> {
65    fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
66}
67
68
69//^
70//^ RANGEFULL
71//^
72
73//> RANGEFULL -> IMPLEMENTATION
74const impl<Type, const N: usize> Index<RangeFull> for Array<Type, N> {
75    type Output = [Type];
76    fn index(&self, index: RangeFull) -> &Self::Output {self.as_ref().index(index)}
77}
78
79//> RANGEFULL -> MUT IMPLEMENTATION
80const impl<Type, const N: usize> IndexMut<RangeFull> for Array<Type, N> {
81    fn index_mut(&mut self, index: RangeFull) -> &mut Self::Output {self.as_mut().index_mut(index)}
82}
83
84
85//^
86//^ RANGEINCLUSIVE
87//^
88
89//> RANGEINCLUSIVE -> IMPLEMENTATION
90const impl<Type, const N: usize> Index<RangeInclusive<usize>> for Array<Type, N> {
91    type Output = [Type];
92    fn index(&self, index: RangeInclusive<usize>) -> &Self::Output {self.as_ref().index(index)}
93}
94
95//> RANGEINCLUSIVE -> MUT IMPLEMENTATION
96const impl<Type, const N: usize> IndexMut<RangeInclusive<usize>> for Array<Type, N> {
97    fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
98}
99
100
101//^
102//^ RANGETO
103//^
104
105//> RANGETO -> IMPLEMENTATION
106const impl<Type, const N: usize> Index<RangeTo<usize>> for Array<Type, N> {
107    type Output = [Type];
108    fn index(&self, index: RangeTo<usize>) -> &Self::Output {self.as_ref().index(index)}
109}
110
111//> RANGETO -> MUT IMPLEMENTATION
112const impl<Type, const N: usize> IndexMut<RangeTo<usize>> for Array<Type, N> {
113    fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
114}
115
116
117//^
118//^ RANGETOINCLUSIVE
119//^
120
121//> RANGETOINCLUSIVE -> IMPLEMENTATION
122const impl<Type, const N: usize> Index<RangeToInclusive<usize>> for Array<Type, N> {
123    type Output = [Type];
124    fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output {self.as_ref().index(index)}
125}
126
127//> RANGETOINCLUSIVE -> MUT IMPLEMENTATION
128const impl<Type, const N: usize> IndexMut<RangeToInclusive<usize>> for Array<Type, N> {
129    fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
130}