-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Add get and get_unchecked to *const [T] and *mut [T] #60639
Copy link
Copy link
Closed
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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