Tracking Issue for feature(ptr_to_from_bits)
· Issue #91126 · rust-lang/rust (original) (raw)
Feature gate: #![feature(ptr_to_from_bits)]
This is a tracking issue for <*const T>::from_bits
, <*mut T>::from_bits
, <*const T>::to_bits
, and <*mut T>::to_bits
.
These, like the stable <*const T>::cast
and <*mut T>::cast
, is proposed as a method for one of the many specific things that as
can do to help increase readability of which of those things is happening, as well as to be able to give better compilation errors (or lints) for suspicious code patterns that aren't necessarily wrong. (For example, p as u32
is legal but suspicious, as it's possible it was meant to be *p as u32
. By having the method, p.to_bits() as u32
is unambiguous.)
See the conversation in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Adding.20methods.20as.20more.20specific.20versions.20of.20.60as.60/near/238391074
Public API
impl *const T { pub fn to_bits(self) -> usize where T: Sized; pub fn from_bits(bits: usize) -> Self where T: Sized; } impl *mut T { pub fn to_bits(self) -> usize where T: Sized; pub fn from_bits(bits: usize) -> Self where T: Sized; }
Steps / History
- Implementation: Add <*{const|mut} T>::{to|from}_bits #91127
- Final comment period (FCP)
- Stabilization PR
Unresolved Questions
- None yet.