by actionfromafar · 3y ago · 0 comments
I was thinking, "that's not how I would design a C++ interface". I still don't understand what these Rust types are good for, but I want to know.
I miss how in Ada you can define which values an int can have. Can you do that in Rust?
yes, kind of: https://crates.io/crates/deranged
It'll take another while until const generics on stable are advanced enough to make this properly usable, such that e.g. `RangedU32<3, 10> + RangedU32<5, 6> = RangedU32<8, 16>`.
type
Subrange = 56..100;
Colors = (Red, Green, Blue);
Pixel = array [Colors] of byte;
With the plus that it is a compiler error if an invalid value is assigned, and can be validated at compile time (or it will be a range runtime error otherwise).