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<T> *const T {
pub fn to_bits(self) -> usize where T: Sized;
pub fn from_bits(bits: usize) -> Self where T: Sized;
}
impl<T> *mut T {
pub fn to_bits(self) -> usize where T: Sized;
pub fn from_bits(bits: usize) -> Self where T: Sized;
}
Steps / History
Unresolved Questions
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>::castand<*mut T>::cast, is proposed as a method for one of the many specific things thatascan 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 u32is legal but suspicious, as it's possible it was meant to be*p as u32. By having the method,p.to_bits() as u32is 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
Steps / History
<*{const|mut} T>::{to|from}_bits#91127Unresolved Questions