@@ -168,6 +168,53 @@ pub trait StructOfArray {
168
168
type Type ;
169
169
}
170
170
171
+
172
+ mod private_soa_indexs {
173
+ // From [`std::slice::SliceIndex`](https://doc.rust-lang.org/std/slice/trait.SliceIndex.html) code.
174
+ // Limits the types that may implement the SoA index traits.
175
+ // It's also helpful to have the exaustive list of all accepted types.
176
+
177
+ use :: std:: ops;
178
+
179
+ pub trait Sealed { }
180
+
181
+ impl Sealed for usize { } // [a]
182
+ impl Sealed for ops:: Range < usize > { } // [a..b]
183
+ impl Sealed for ops:: RangeTo < usize > { } // [..b]
184
+ impl Sealed for ops:: RangeFrom < usize > { } // [a..]
185
+ impl Sealed for ops:: RangeFull { } // [..]
186
+ impl Sealed for ops:: RangeInclusive < usize > { } // [a..=b]
187
+ impl Sealed for ops:: RangeToInclusive < usize > { } // [..=b]
188
+ }
189
+
190
+ /// Helper trait used for indexing operations.
191
+ /// Inspired by [`std::slice::SliceIndex`](https://doc.rust-lang.org/std/slice/trait.SliceIndex.html).
192
+ pub trait SoaIndex < T > : private_soa_indexs:: Sealed {
193
+ /// The output for the non-mutable functions
194
+ type RefOutput ;
195
+
196
+ /// Returns the reference output in this location if in bounds. None otherwise.
197
+ fn get ( self , soa : T ) -> Option < Self :: RefOutput > ;
198
+ /// Returns the reference output in this location withotu performing any bounds check.
199
+ unsafe fn get_unchecked ( self , soa : T ) -> Self :: RefOutput ;
200
+ /// Returns the reference output in this location. Panics if it is not in bounds.
201
+ fn index ( self , soa : T ) -> Self :: RefOutput ;
202
+ }
203
+
204
+ /// Helper trait used for indexing operations returning mutable.
205
+ /// Inspired by [`std::slice::SliceIndex`](https://doc.rust-lang.org/std/slice/trait.SliceIndex.html).
206
+ pub trait SoaMutIndex < T > : private_soa_indexs:: Sealed {
207
+ /// The output for the mutable functions
208
+ type MutOutput ;
209
+
210
+ /// Returns the mutable reference output in this location if in bounds. None otherwise.
211
+ fn get_mut ( self , soa : T ) -> Option < Self :: MutOutput > ;
212
+ /// Returns the mutable reference output in this location withotu performing any bounds check.
213
+ unsafe fn get_unchecked_mut ( self , soa : T ) -> Self :: MutOutput ;
214
+ /// Returns the mutable reference output in this location. Panics if it is not in bounds.
215
+ fn index_mut ( self , soa : T ) -> Self :: MutOutput ;
216
+ }
217
+
171
218
/// Create an iterator over multiple fields in a Struct of array style vector.
172
219
///
173
220
/// This macro takes two main arguments: the array/slice container, and a list
0 commit comments