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_highest_one(self) -> Self;
const fn isolate_lowest_one(self) -> Self;
}
impl {i8, i16, i32, i64, i128, isize} {
const fn isolate_highest_one(self) -> Self;
const fn isolate_lowest_one(self) -> Self;
}
impl NonZeroT {
const fn isolate_highest_one(self) -> Self;
const fn isolate_lowest_one(self) -> Self;
}
Steps / History
Unresolved Questions
Function name length
RESOLVED - #136909 (comment)
Functions have been renamed to isolate_highest_one/isolate_lowest_one
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):
isolate_least_significant_one / isolate_most_significant_one
least_sig_one / most_sig_one
lowest_one / highest_one
lowest_bit_set / highest_bit_set
isolate_lowest_one / isolate_highest_one
trailing_one / leading_one
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
NonZeroTinteger types.Public API
Steps / History
least_significant_oneandmost_significant_oneto integer types andNonZerotypes libs-team#467isolate_most_least_significant_onefor integer types #136910isolate_most_least_significant_onefunctions #144971Unresolved Questions
Function name lengthRESOLVED - #136909 (comment)
Functions have been renamed to
isolate_highest_one/isolate_lowest_oneThe 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,
isolateis suggested as a prefix to disambiguate the meaning.Possible names (non-exhaustive):
isolate_least_significant_one/isolate_most_significant_oneleast_sig_one/most_sig_onelowest_one/highest_onelowest_bit_set/highest_bit_setisolate_lowest_one/isolate_highest_onetrailing_one/leading_oneFootnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩