Describe the bug
Because buf.bit_slice(...) falls back to a slice that ignores the length when the offset is byte-aligned, the resulting buffer has an incorrect length. This leads to problems when applying bitwise operations such as &, for instance.
To Reproduce
The following test fails:
#[test]
fn test_bit_slice_aligned() {
let buf = Buffer::from(&[2, 4, 6, 8, 10]);
let slice = buf.bit_slice(8, 8);
let expected = Buffer::from(&[4]);
assert_eq!(slice.len(), 1); // actual length is 4!!
assert_eq!(&slice, &expected);
}
Expected behavior
Test passes.
Additional context
Add any other context about the problem here.