Open
Description
A simple enhancement request. I think in line with the idea of Rust design to give low level control, to offer an ergonomic API that reduces the chances for bugs while keeping code efficient, and at the same time avoiding too many special operators, I think Rust stdlib could add few simple functions to work on bits of integral values (u8, i8, ...etc, usize, isize and char):
x.set_bit(7);
x.set_bit(1 ..= 3);
x.reset_bit(7);
x.reset_bit(1 .. 5);
x.invert_bit(7);
x.invert_bit(2 ..);
if x.is_bit_set(7) {} // For simplicity this accepts only single indexes.
if x.is_bit_reset(7) {}
Such functions can be implemented in user level code, in just a handful of lines, but they are twiddly and it's boring to implement them many times (especially the interval ones), so having them in the stdlib saves bugs, time and allows to focus on more interesting code :-)