Tracking Issue for integer_sign_cast · Issue #125882 · rust-lang/rust (original) (raw)

Feature gate: #![feature(integer_sign_cast)]

This is a tracking issue for explicit signedness casting methods for integer primitive types. Libs discussion: rust-lang/libs-team#359.

Public API

(for N in [8, 16, 32, 64, 128, size]):

impl uN { pub const fn cast_signed(self) -> iN {} }

impl iN { pub const fn cast_unsigned(self) -> uN {} }

impl NonZero { pub const fn cast_signed(self) -> NonZero {} }

impl NonZero { pub const fn cast_unsigned(self) -> NonZero {} }

Steps / History

Unresolved Questions

Mostly bikeshedding regarding naming, as mentioned in the Libs discussion. The current proposal follows the naming of cast_const and cast_mut for pointers.

Alternatively, these could be implemented as from_bits and to_bits methods for the signed types.

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html