ferrilab / bitvec

A crate for managing memory bit by bit
https://myrrlyn.net/crates/bitvec
MIT License
1.2k stars 115 forks source link

BitVec.BitAnd requiring a mutable reference to self? #177

Closed Pr0gm4n closed 2 years ago

Pr0gm4n commented 2 years ago

I am using the bitvec::prelude::BitVec package and want to perform some bitwise manipulations such as &, i.e. BitAnd. When scrolling the documentation, I've noticed that the source code unexpectedly reveals that this call would require a mutable reference to self, as well as using the &= operator in the function body. Do I misinterpret something here, or is the & operator really changing the value of the left hand side object?

From bitvec-1.0.0/src/vec/ops.rs:

#[cfg(not(tarpaulin_include))]
impl<T, O, Rhs> BitAnd<Rhs> for BitVec<T, O>
where
    T: BitStore,
    O: BitOrder,
    BitSlice<T, O>: BitAndAssign<Rhs>,
{
    type Output = Self;

    fn bitand(mut self, rhs: Rhs) -> Self::Output {
        self &= rhs;
        self
    }
}
Pr0gm4n commented 2 years ago

A colleague just pointed me to this comment: https://github.com/bitvecto-rs/bitvec/issues/54#issuecomment-605109794

I think that answers my question.