← Back to context

Comment by wongarsu

5 hours ago

There is nook which does it with unstable features [1] and nonany [2] which uses xor operations to map your custom niche value to 0 so it can use the NonZero* types to achieve the same in stable rust.

Eventually rust will likely gain pattern types as a more generally useful version of the features used in nook. There is even some actively ongoing work on this [3]

1: https://github.com/tialaramex/nook/blob/main/src/balanced.rs

2: https://github.com/rick-de-water/nonany

3: https://github.com/rust-lang/rust/issues/135996