Re:When zero cost abstractions aren't zero cost
by estebank on Tuesday August 10, 2021 @11:54AM
(#28130390)
The comment is fair. There have been some talks about being able to allow end users specify niches so that if you could have something like
in the same way that the following is of size T today
but that's not possible today.
[ Parent
| on HN ]
Re:When zero cost abstractions aren't zero cost
by tialaramex on Tuesday August 10, 2021 @01:45PM
(#28131887)
Yes, I can see uses for this. Forty-two is obviously not something you'd actually want, but I can see needing numbers in the range 0-100 and being frustrated that since I need 0 I can't carve out a niche even though I don't mind losing 101 through 255 from a u8 instead of making my type wider.
Still the existing tricks get a lot done for relatively little work. I have used Option<NonZeroUsize> to do roughly what I'd use a single integer for in C, but making explicit that zero isn't just zero, but "I dunno, invalid". Would I have done that even if it cost more space? Probably, but it was cool that I didn't even need to consider that, "Zero cost abstraction".