Skip to content

Commit 2108aad

Browse files
committed
Document remaining methods
1 parent c82b35d commit 2108aad

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/volatile_ptr/unstable.rs

+27
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ use crate::{
1111
};
1212

1313
impl<'a, T, A> VolatilePtr<'a, [T], A> {
14+
/// Returns the length of the slice.
1415
pub fn len(self) -> usize {
1516
self.pointer.len()
1617
}
1718

19+
/// Returns whether the slice is empty.
1820
pub fn is_empty(self) -> bool {
1921
self.pointer.len() == 0
2022
}
@@ -239,6 +241,16 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
239241
}
240242
}
241243

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+
///
242254
pub fn split_at(self, mid: usize) -> (VolatilePtr<'a, [T], A>, VolatilePtr<'a, [T], A>)
243255
where
244256
A: Access,
@@ -265,6 +277,13 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
265277
}
266278
}
267279

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.
268287
pub fn as_chunks<const N: usize>(
269288
self,
270289
) -> (VolatilePtr<'a, [[T; N]], A>, VolatilePtr<'a, [T], A>)
@@ -280,6 +299,14 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
280299
(array_slice, remainder)
281300
}
282301

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`.
283310
pub unsafe fn as_chunks_unchecked<const N: usize>(self) -> VolatilePtr<'a, [[T; N]], A>
284311
where
285312
A: Access,

src/volatile_ptr/very_unstable.rs

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ impl<'a, T, A> VolatilePtr<'a, T, A>
66
where
77
T: ?Sized,
88
{
9+
/// Compile-time evaluable variant of [`Self::map`].
10+
///
11+
/// This function is a copy of [`Self::map`] that uses unstable compiler functions
12+
/// to be callable from `const` contexts.
13+
///
14+
/// ## Safety
15+
///
16+
/// The safety requirements of [`Self::map`] apply to this method too.
917
pub const unsafe fn map_const<F, U>(self, f: F) -> VolatilePtr<'a, U, A>
1018
where
1119
F: ~const FnOnce(NonNull<T>) -> NonNull<U>,
@@ -18,6 +26,10 @@ where
1826
/// Methods for volatile slices
1927
#[cfg(feature = "unstable")]
2028
impl<'a, T, A> VolatilePtr<'a, [T], A> {
29+
/// Compile-time evaluable variant of [`Self::index`].
30+
///
31+
/// This function is a copy of [`Self::index`] that uses unstable compiler functions
32+
/// to be callable from `const` contexts.
2133
pub const fn index_const(self, index: usize) -> VolatilePtr<'a, T, A> {
2234
assert!(index < self.pointer.len(), "index out of bounds");
2335

0 commit comments

Comments
 (0)