4 ms·
AIUI The sticky problem is that the Rust compiler today wants to see a single contiguous range of scalar values to enable this trick and from its perspective e.
by tialaramex 4y ago
AIUI The sticky problem is that the Rust compiler today wants to see a single contiguous range of scalar values to enable this trick and from its perspective e.g. BalancedI8 would have two ranges, 0 to 127 inclusive and then 129 to 255 inclusive, it doesn't see the signed interpretation when thinking about this problem.
That's clearly not impossible to solve, but if I'm correct it means significant compiler development work rather than just a fun weekend chore writing and testing a custom type intended to work only in the standard library.
- codeflo 4y agoIt’s obviously 129 to 127 inclusive, hoping that the implied unsigned overflow has the correct consequences. ;)
- tialaramex 4y agoWoah, that actually seems to work. My toy Option<BalancedI8> compiles and works (in a hacked environment).