Tracking Issue for isolate_most_least_significant_one · Issue #136909 · rust-lang/rust (original) (raw)

Feature gate: #![feature(isolate_most_least_significant_one)]

This is a tracking issue for functions that return an integer with only the most significant set bit or only the least significant set bit masked from the input integer.

The functions are implemented for unsigned, signed, and NonZeroT integer types.

Public API

impl {u8, u16, u32, u64, u128, usize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl {i8, i16, i32, i64, i128, isize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl NonZeroT { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; }

Steps / History

Unresolved Questions

Function name length

The initial function names are taken from the libs-api suggestions in the ACP, but they are quite verbose.

The names need to indicate that the integer being returned is the input with only the most/least significant set bit and not whether the most/least significant bit is 0 or 1. Hence, isolate is suggested as a prefix to disambiguate the meaning.

assert_eq!(u8::isolate_most_significant_one(0b01100100), 0b01000000); assert_eq!(u8::isolate_least_significant_one(0b01100100), 0b00000100);

Possible names (non-exhaustive):

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