Could you borrow a bit?
Rust Internals [Unofficial]
May 18, 2026
bascule:
A particularly fun question for bitstring reference type libraries like what I'm writing is: is how do you implement
split_at_mut?
I think it should be possible by not restricting ourselves to relying on references.
As I wrote in the other discussion, a quasi-reference type like this could work:
struct BitSliceMut<'a> {
origin_ptr: *mut u8,
bit_offset: usize,
bit_len: usize,
_pd: PhantomData<&'a mut u8>,
}
By keeping it non-Send it should be possible to construct a safe API for creating (e.g. with split_at_mut) and manipulating such type.
Yes, there is a number of unfortunate ergonomic issues with such custom reference types, but IMO it's the most practical option right now.
Discussion in the ATmosphere