External Publication
Visit Post

`BitSlice` or a sound way to implement one

Rust Internals [Unofficial] April 23, 2026
Source

Why is bitvec implemented with a reference instead of a raw pointer like *const u8 or *const () (alongside a separate length field, and PhantomData for the lifetime)? I'll try to keep looking through the bitvec repo to figure out the motivation, but a quick look through its Issues didn't give me any information.

Edit: even *const [u8] ( + PhantomData for the lifetime) would work.

bascule:

Alternatively, if there were unsafe APIs that could take apart a fat pointer and put it back together while preserving provenance, but allow the caller to carry along some additional data in the length field, kind of like the addr/with_addr/map_addr APIs for tagged pointers work, that could also do the trick.

I feel like "raw pointers instead of references" is precisely this API, unless there's some critical optimization that isn't applied with that solution.

Edit again: ahhhhh, the problem is Borrow and friends.

Discussion in the ATmosphere

Loading comments...