-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
as_(mut_)ptr and as_(mut_)slice methods on raw array pointers #321
Comments
We discussed this during today's libs-API meeting. We're ok accepting these methods as unstable additions. But stabilization will likely be blocked on the |
Add as_(mut_)ptr and as_(mut_)slice to raw array pointers Hey, first time contributing to the standard libraries so not completely sure about the process. These functions are complementary to the ones being added in rust-lang#74265 . I found them missing on array pointers. See also: - ACP: rust-lang/libs-team#321 - Tracking issue: rust-lang#119834
Add as_(mut_)ptr and as_(mut_)slice to raw array pointers Hey, first time contributing to the standard libraries so not completely sure about the process. These functions are complementary to the ones being added in rust-lang#74265 . I found them missing on array pointers. See also: - ACP: rust-lang/libs-team#321 - Tracking issue: rust-lang#119834
Rollup merge of rust-lang#119411 - yotamofek:array-ptr-get, r=Nilstrieb Add as_(mut_)ptr and as_(mut_)slice to raw array pointers Hey, first time contributing to the standard libraries so not completely sure about the process. These functions are complementary to the ones being added in rust-lang#74265 . I found them missing on array pointers. See also: - ACP: rust-lang/libs-team#321 - Tracking issue: rust-lang#119834
Proposal
Add
as_(mut_)ptr
methods to raw array pointers (*(const/mut) [T; N]
) as in theslice_ptr_get
feature to allow for type-safe casting of*[T; N]
to*T
, andas_(mut_)slice
as a safe way to convert a*[T; N]
into a*[T]
.Problem statement
The ergonomics for raw array pointers are lacking behind from those for raw slices.
I also think that
get_unchecked(_mut)
should at some point be available for array pointers, but IMHO there are const-generic-related implications to trying to stabilize that, while I believe these methods might have fewer blockers.Motivating examples or use cases
Array-based ring buffer crate I wrote for fun:
https://github.com/yotamofek/ring-buffer/blob/11efcc6ba80a9bb7ad65ef491d8746cf132f4eb4/src/iter.rs#L36C17-L38C40
Doing ptr arithmetic on raw arrays/slices is scary because if you end up doing
ptr.add(..)
on a*[T;N]
instead of a*T
that could have really bad implications. The methods I'm proposing here could help me write the cast more explicitly, and theas_(mut_)slice
method could also allow me to use the raw slice methods on my ptr (sorta like how autoderef allows using slice methods on non-raw-arrays).Solution sketch
rust-lang/rust#119411
Alternatives
Could be implemented in a 3rd party crate with extension trait, I guess.
Links and related work
rust-lang/rust#74265
rust-lang/rust#73986
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: