`BitSlice` or a sound way to implement one
Rust Internals [Unofficial]
April 24, 2026
For anyone not already aware of roughly what the problem is: Rust basically has a few stable ways of supporting “higher-kinded types” (HKTs), which are families of types, like Vec (without a <T>).
Here are the three stable mechanisms for HKTs with one lifetime parameter:
- You can denote the HKT family
&'varying Twith by justT, and feed the HKT a'varyingparameter to get&'varying T. - You can use a generic associated type (GAT) like
trait GatHKT { type Apply<'varying>; }, perhaps to make aGatDerefequivalent ofstd’sDeref. - You can use higher-kinded trait bounds (like
for<'varying> Trait<'varying>) to do something insane like myvariance-familycrate — which is thousands of lines of code long — to try to get much more thorough support for lifetime-parameterized HKTs.
Each of these three options has problems. The first isn’t fully general. The second interacts poorly with higher-kinded trait bounds. The third involves several unsafe traits and presumably isn’t fit for std.
std uses the first option, which means its traits aren’t as general as possible.
Discussion in the ATmosphere