Skip to content

Tracking Issue for feature(ptr_to_from_bits) #91126

Closed
@scottmcm

Description

@scottmcm

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

  • None yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions