@@ -11,10 +11,12 @@ use crate::{
11
11
} ;
12
12
13
13
impl < ' a , T , A > VolatilePtr < ' a , [ T ] , A > {
14
+ /// Returns the length of the slice.
14
15
pub fn len ( self ) -> usize {
15
16
self . pointer . len ( )
16
17
}
17
18
19
+ /// Returns whether the slice is empty.
18
20
pub fn is_empty ( self ) -> bool {
19
21
self . pointer . len ( ) == 0
20
22
}
@@ -239,6 +241,16 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
239
241
}
240
242
}
241
243
244
+ /// Divides one slice into two at an index.
245
+ ///
246
+ /// The first will contain all indices from `[0, mid)` (excluding
247
+ /// the index `mid` itself) and the second will contain all
248
+ /// indices from `[mid, len)` (excluding the index `len` itself).
249
+ ///
250
+ /// # Panics
251
+ ///
252
+ /// Panics if `mid > len`.
253
+ ///
242
254
pub fn split_at ( self , mid : usize ) -> ( VolatilePtr < ' a , [ T ] , A > , VolatilePtr < ' a , [ T ] , A > )
243
255
where
244
256
A : Access ,
@@ -265,6 +277,13 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
265
277
}
266
278
}
267
279
280
+ /// Splits the slice into a slice of `N`-element arrays,
281
+ /// starting at the beginning of the slice,
282
+ /// and a remainder slice with length strictly less than `N`.
283
+ ///
284
+ /// # Panics
285
+ ///
286
+ /// Panics if `N` is 0.
268
287
pub fn as_chunks < const N : usize > (
269
288
self ,
270
289
) -> ( VolatilePtr < ' a , [ [ T ; N ] ] , A > , VolatilePtr < ' a , [ T ] , A > )
@@ -280,6 +299,14 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
280
299
( array_slice, remainder)
281
300
}
282
301
302
+ /// Splits the slice into a slice of `N`-element arrays,
303
+ /// assuming that there's no remainder.
304
+ ///
305
+ /// # Safety
306
+ ///
307
+ /// This may only be called when
308
+ /// - The slice splits exactly into `N`-element chunks (aka `self.len() % N == 0`).
309
+ /// - `N != 0`.
283
310
pub unsafe fn as_chunks_unchecked < const N : usize > ( self ) -> VolatilePtr < ' a , [ [ T ; N ] ] , A >
284
311
where
285
312
A : Access ,
0 commit comments