2 ms·
You can make it on stable Rust by using an enum with a missing variant. The compiler will give you a niche automatically. Of course that doesn't scale to large
by veber-alex 3y ago
You can make it on stable Rust by using an enum with a missing variant.
The compiler will give you a niche automatically.
Of course that doesn't scale to larger types as even with a macro the compile speed will be horrible.
- tialaramex 3y agoYeah, "enum with a missing variant" is like, awful but maybe viable for BalancedI8, but it's clearly insane for BalancedI32 let alone BalancedI64 and those seem at least as useful. Today, in practice, if you want BalancedI32 what you'd do is swizzle NonZeroI32, so that a trivial CPU operation converts between the two types and you can deliver almost the same optimisations in practice. But, I think that's also pretty ugly, and Rust clearly could do the nicer thing here, indeed it does in my crate that only builds on nightly and is using not-for-public-use compiler internal attributes. So that's what I want, just apparently not enough to spend my vacation time last month working on it. Maybe next month.