Closed simo498 closed 2 years ago
@simo498 here I appreciate more feedback also from @AlessandroGrassi99 and @gallottino
But sure I prefer this kind of api not for a struct Bitwise
but as implementation of u32
or such... In this way you can do my_number.toggle_bit(15)
and this will toggle the bit 15.
I have some doubt also if is better is_set/is_reset
but let's discuss :D
@simo498 here I appreciate more feedback also from @AlessandroGrassi99 and @gallottino But sure I prefer this kind of api not for a struct
Bitwise
but as implementation ofu32
or such... In this way you can domy_number.toggle_bit(15)
and this will toggle the bit 15. I have some doubt also if is betteris_set/is_reset
but let's discuss :D
Yeah it's an idea. Another is to create a wrapper like Bitwise(u32)
. Anyway let's hear the opinion of other people on which implementation we should uses. I also think something more direct like u32::get_bit
or whatever would be more readable
I implemented the methods to u32 directly, so they can be called by just adding use crate::bitwise::Bits
, i also added rand
for testing, but it can be useful in the future as well
It adds some methods to check and set single bits. For now there aren't methods to handle multiple bits masks, and it's limited to u32 (due to the assence of a common Integer trait in rust).
Refers to #33