Feature request: From<&[T]> for NonNull<T> #69316
Labels
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
While
NonNull<T>
implementsFrom<&T>
, it does not implementFrom<&[T]>
. Current options:NonNull::new(slice.as_ptr() as *mut T).unwrap()
, and rely on the optimizer to remove the unwrap.unsafe { NonNull::new_unchecked(slice.as_ptr() as *mut T) }
, which is correct but unfortunately has to useunsafe
.NonNull::from(&slice[0])
, which looks more ergonomic than 1 and 2, but has incorrect pointer provenance.Since both references and slices have
as_ptr
andas_mut_ptr
methods, I think thatNonNull
should implementFrom
for slices as well as for references.The text was updated successfully, but these errors were encountered: