When loading a slice of bitvec as u8 I am not getting the expected result when bitvec order does not match big/little endian. Here's example code showing the issue:
use bitvec::prelude::*; use rand::Rng; let mut rng = rand::rng(); let mut bv: BitVec<u8, Msb0> = BitVec::with_capacity(1000); for _ in 0..1000 { bv.push(rng.random()); } let idx_to_print = 159; let bslice = &bv[idx_to_print..idx_to_print+8]; let val: u8 = bslice.load_le(); println!("Bitvec: {:?}, Orig: {:b}",bslice, val); This gives me result:
Bitvec: BitSlice<u8, bitvec::order::Msb0> { addr: 0x5e32ef0bb243, head: 111, bits: 8 } [1, 1, 1, 1, 1, 0, 0, 1], Orig: 11110011 Now things are fine when bitvec order and big/little endian are aligned. And there's no reason I should be using this call. BUT - shouldn't the bits here simply be reversed? They are not.
Msb0inbitvectalks about the bit ordering, not the byte ordering.load_le()is talking about byte order, andMsb0is talking about bit order. At least from how I understand the docs.Lsb0withload_le, it works. If you useMsb0withload_be, it works. So clearly they somehow influence each other.