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    #[inline]
29    fn index(&self, index: usize) -> &Self::Output {self.get(index).unwrap()}
30}
31
32//> USIZE -> MUT IMPLEMENTATION
33const impl<Type, const N: usize> IndexMut<usize> for Array<Type, N> {
34    #[inline]
35    fn index_mut(&mut self, index: usize) -> &mut Self::Output {self.get_mut(index).unwrap()}
36}
37
38
39//^
40//^ RANGE
41//^
42
43//> RANGE -> IMPLEMENTATION
44const impl<Type, const N: usize> Index<Range<usize>> for Array<Type, N> {
45    type Output = [Type];
46    #[inline]
47    fn index(&self, index: Range<usize>) -> &Self::Output {self.as_ref().index(index)}
48}
49
50//> RANGE -> MUT IMPLEMENTATION
51const impl<Type, const N: usize> IndexMut<Range<usize>> for Array<Type, N> {
52    #[inline]
53    fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
54}
55
56
57//^
58//^ RANGEFROM
59//^
60
61//> RANGEFROM -> IMPLEMENTATION
62const impl<Type, const N: usize> Index<RangeFrom<usize>> for Array<Type, N> {
63    type Output = [Type];
64    #[inline]
65    fn index(&self, index: RangeFrom<usize>) -> &Self::Output {self.as_ref().index(index)}
66}
67
68//> RANGEFROM -> MUT IMPLEMENTATION
69const impl<Type, const N: usize> IndexMut<RangeFrom<usize>> for Array<Type, N> {
70    #[inline]
71    fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
72}
73
74
75//^
76//^ RANGEFULL
77//^
78
79//> RANGEFULL -> IMPLEMENTATION
80const impl<Type, const N: usize> Index<RangeFull> for Array<Type, N> {
81    type Output = [Type];
82    #[inline]
83    fn index(&self, index: RangeFull) -> &Self::Output {self.as_ref().index(index)}
84}
85
86//> RANGEFULL -> MUT IMPLEMENTATION
87const impl<Type, const N: usize> IndexMut<RangeFull> for Array<Type, N> {
88    #[inline]
89    fn index_mut(&mut self, index: RangeFull) -> &mut Self::Output {self.as_mut().index_mut(index)}
90}
91
92
93//^
94//^ RANGEINCLUSIVE
95//^
96
97//> RANGEINCLUSIVE -> IMPLEMENTATION
98const impl<Type, const N: usize> Index<RangeInclusive<usize>> for Array<Type, N> {
99    type Output = [Type];
100    #[inline]
101    fn index(&self, index: RangeInclusive<usize>) -> &Self::Output {self.as_ref().index(index)}
102}
103
104//> RANGEINCLUSIVE -> MUT IMPLEMENTATION
105const impl<Type, const N: usize> IndexMut<RangeInclusive<usize>> for Array<Type, N> {
106    #[inline]
107    fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
108}
109
110
111//^
112//^ RANGETO
113//^
114
115//> RANGETO -> IMPLEMENTATION
116const impl<Type, const N: usize> Index<RangeTo<usize>> for Array<Type, N> {
117    type Output = [Type];
118    #[inline]
119    fn index(&self, index: RangeTo<usize>) -> &Self::Output {self.as_ref().index(index)}
120}
121
122//> RANGETO -> MUT IMPLEMENTATION
123const impl<Type, const N: usize> IndexMut<RangeTo<usize>> for Array<Type, N> {
124    #[inline]
125    fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
126}
127
128
129//^
130//^ RANGETOINCLUSIVE
131//^
132
133//> RANGETOINCLUSIVE -> IMPLEMENTATION
134const impl<Type, const N: usize> Index<RangeToInclusive<usize>> for Array<Type, N> {
135    type Output = [Type];
136    #[inline]
137    fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output {self.as_ref().index(index)}
138}
139
140//> RANGETOINCLUSIVE -> MUT IMPLEMENTATION
141const impl<Type, const N: usize> IndexMut<RangeToInclusive<usize>> for Array<Type, N> {
142    #[inline]
143    fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output {self.as_mut().index_mut(index)}
144}