bitvec icon indicating copy to clipboard operation
bitvec copied to clipboard

Difference between `BitVec` and `BitVec<T, O>`?

Open avdb13 opened this issue 2 years ago • 1 comments

The following compiles:

pub struct BitMap {
    inner: Receiver<Vec<u8>>,
    rare_bits: BitVec<u8, Msb0>,
}

impl BitMap {
    async fn recv(&mut self) {
        let next = self.inner.recv().await.unwrap();
        let rhs = BitVec::from_vec(next);

        self.rare_bits.bitxor_assign(rhs);
    }
}

But the following doesn't:

pub struct BitMap {
    inner: Receiver<Vec<u8>>,
    rare_bits: BitVec,
}

impl BitMap {
    async fn recv(&mut self) {
        let next = self.inner.recv().await.unwrap();
        let rhs = BitVec::from_vec(next);

       // no implementation for `BitSlice ^= BitVec<u8, _>`
        self.rare_bits.bitxor_assign(rhs);
    }
}

What are the semantic differences here?

avdb13 avatar Jul 17 '23 09:07 avdb13

The default is to use usize and Lsb0 so in the second example rare_bits is of type BitVec<usize, Lsb0>.

mina86 avatar Dec 04 '23 14:12 mina86