ferrilab / bitvec

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

Implement `Send` for `BitValIter` #258

Open akoshelev opened 9 months ago

akoshelev commented 9 months ago

Currently Iter and BitValIter have identical bodies, but only the former implements Send.

#[repr(transparent)]
#[doc = include_str!("../../doc/slice/iter/Iter.md")]
pub struct Iter<'a, T, O>
where
    T: 'a + BitStore,
    O: BitOrder,
{
    /// A dual-pointer range of the bit-slice undergoing iteration.
    ///
    /// This structure stores two fully-decode pointers to the first live and
    /// first dead bits, trading increased size (three words instead of two) for
    /// faster performance when iterating.
    range: BitPtrRange<Const, T, O>,
    /// `Iter` is semantically equivalent to a `&BitSlice`.
    _ref:  PhantomData<&'a BitSlice<T, O>>,
}

...

pub struct BitValIter<'a, T, O>
where
    T: 'a + BitStore,
    O: BitOrder,
{
    /// The start and end bit-pointers in the iteration region.
    range: BitPtrRange<Const, T, O>,
    /// Hold the lifetime of the source region, so that this does not cause UAF.
    _life: PhantomData<&'a BitSlice<T, O>>,
}

It would be nice if BitValIter could also implement Send so it can be used as a direct replacement for Iter where bool values are needed