alloc_no_stdlib/allocated_memory/
index_macro.rs
1#[macro_export]
2macro_rules! define_index_ops_mut {
3 ($T:ident, $MemoryType:ty) => {
4 impl<$T> ::core::ops::Index<usize> for $MemoryType
5 {
6 type Output = T;
7
8 #[inline]
9 fn index(&self, index: usize) -> &Self::Output {
10 ::core::ops::Index::index(&**self, index)
11 }
12 }
13
14 impl<$T> ::core::ops::IndexMut<usize> for $MemoryType
15 {
16 #[inline]
17 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
18 ::core::ops::IndexMut::index_mut(&mut **self, index)
19 }
20 }
21
22
23 impl<$T> ::core::ops::Index<::core::ops::Range<usize>> for $MemoryType
24 {
25 type Output = [T];
26 #[inline]
27 fn index(&self, index: ::core::ops::Range<usize>) -> &Self::Output {
28 ::core::ops::Index::index(&**self, index)
29 }
30 }
31
32 impl<$T> ::core::ops::IndexMut<::core::ops::Range<usize>> for $MemoryType
33 {
34 #[inline]
35 fn index_mut(&mut self, index: ::core::ops::Range<usize>) -> &mut Self::Output {
36 ::core::ops::IndexMut::index_mut(&mut **self, index)
37 }
38 }
39
40
41 impl<$T> ::core::ops::Deref for $MemoryType {
42 type Target = [T];
43
44 fn deref(&self) -> &[T] {
45 self.slice()
46 }
47 }
48
49 impl<T> ::core::ops::DerefMut for $MemoryType {
50 fn deref_mut(&mut self) -> &mut [T] {
51 self.slice_mut()
52 }
53 }
54 };
55 ($T0: ident, $T:ident, $MemoryType:ty) => {
56 impl<'a, $T> ::core::ops::Index<usize> for $MemoryType
57 {
58 type Output = T;
59
60 #[inline]
61 fn index(&self, index: usize) -> &Self::Output {
62 ::core::ops::Index::index(&**self, index)
63 }
64 }
65
66 impl<'a, $T> ::core::ops::IndexMut<usize> for $MemoryType
67 {
68 #[inline]
69 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
70 ::core::ops::IndexMut::index_mut(&mut **self, index)
71 }
72 }
73
74
75 impl<'a, $T> ::core::ops::Index<::core::ops::Range<usize>> for $MemoryType
76 {
77 type Output = [T];
78
79 #[inline]
80 fn index(&self, index: ::core::ops::Range<usize>) -> &Self::Output {
81 ::core::ops::Index::index(&**self, index)
82 }
83 }
84
85
86 impl<'a, $T> ::core::ops::IndexMut<::core::ops::Range<usize>> for $MemoryType
87 {
88 #[inline]
89 fn index_mut(&mut self, index: ::core::ops::Range<usize>) -> &mut Self::Output {
90 ::core::ops::IndexMut::index_mut(&mut **self, index)
91 }
92 }
93
94
95 impl<'a, $T> ::core::ops::Deref for $MemoryType {
96 type Target = [T];
97
98 fn deref(&self) -> &[T] {
99 self.slice()
100 }
101 }
102 impl<'a, $T> ::core::ops::DerefMut for $MemoryType {
103 fn deref_mut(&mut self) -> &mut [T] {
104 self.slice_mut()
105 }
106 }
107 }
108}
109#[macro_export]
110macro_rules! define_index_ops {
111 ($T:ident, $MemoryType:ty) => {
112 impl<$T> ::core::ops::Index<usize> for $MemoryType
113 {
114 type Output = T;
115
116 #[inline]
117 fn index(&self, index: usize) -> &Self::Output {
118 ::core::ops::Index::index(&**self, index)
119 }
120 }
121
122
123 impl<$T> ::core::ops::Index<::core::ops::Range<usize>> for $MemoryType
124 {
125 type Output = [T];
126
127 #[inline]
128 fn index(&self, index: ::core::ops::Range<usize>) -> &Self::Output {
129 ::core::ops::Index::index(&**self, index)
130 }
131 }
132
133 impl<$T> ::core::ops::Deref for $MemoryType {
134 type Target = [T];
135
136 fn deref(&self) -> &[T] {
137 self.slice()
138 }
139 }
140
141 };
142 ($T0: tt, $T:ident, $MemoryType:ty) => {
143 impl<'a, $T> ::core::ops::Index<usize> for $MemoryType
144 {
145 type Output = T;
146
147 #[inline]
148 fn index(&self, index: usize) -> &Self::Output {
149 ::core::ops::Index::index(&**self, index)
150 }
151 }
152
153 impl<'a, $T> ::core::ops::Index<::core::ops::Range<usize>> for $MemoryType
154 {
155 type Output = [T];
156
157 #[inline]
158 fn index(&self, index: ::core::ops::Range<usize>) -> &Self::Output {
159 ::core::ops::Index::index(&**self, index)
160 }
161 }
162
163
164 impl<'a, $T> ::core::ops::Deref for $MemoryType {
165 type Target = [T];
166
167 fn deref(&self) -> &[T] {
168 self.slice()
169 }
170 }
171 }
172}