If one has a *const [T] and wants a pointer to a specific element of that slice, one needs to go through a reference and index, or cast the pointer to *const T and offset that by the number of elements (which doesn't do a length check, so you need that, too). I propose that we add two new methods to *const [T] and *mut [T]:
impl<T> *const [T] {
fn get(self, idx: usize) -> Option<*const T>;
unsafe fn get_unchecked(self, idx: usize) -> *const T;
}
get_unchecked is unsafe, because if a large index is used, one may overflow the pointer, which is UB
To make the implementation of get simpler, I propose to additionally add a len method:
impl<T> *const [T] {
fn len(self) -> usize;
}
cc @RalfJung @shepmaster
If one has a
*const [T]and wants a pointer to a specific element of that slice, one needs to go through a reference and index, or cast the pointer to*const Tand offset that by the number of elements (which doesn't do a length check, so you need that, too). I propose that we add two new methods to*const [T]and*mut [T]:get_uncheckedis unsafe, because if a large index is used, one may overflow the pointer, which is UBTo make the implementation of
getsimpler, I propose to additionally add alenmethod:cc @RalfJung @shepmaster