Function bitfrob::u8_with_region
source · pub const fn u8_with_region(low: u32, high: u32, old: u8, replacement: u8) -> u8Expand description
Replaces the low to high bit region of old.
The low and high values form an inclusive bit range.
Bits in replacement outside of the region have no effect.
Panics
lowandhighcan’t exceed the number of bits in the type.lowmust be less thanhigh.
assert_eq!(u8_with_region(0, 2, 0b11111111_u8, 0), 0b1111_1000_u8);
assert_eq!(u8_with_region(1, 3, 0b11111111_u8, 0), 0b1111_0001_u8);
assert_eq!(u8_with_region(4, 7, 0b11111111_u8, 0), 0b0000_1111_u8);