With const generics we'll be able to write a little nonzero function that takes the number and returns a value like a NonZeroU32 without the need for unwrap (or pattern matching) because the test is done at compile-time. And we can also support iteration on values like NonZeroU32, so we'll be able to write code like:
use std::num::*;
fn main() {
for nz in nonzero::<1_u32>() .. nonzero::<10_u32>() {
println!("{:?}", nz);
}
}
(Perhaps the second _u32
could be omitted).
Once we have ranged integral types in Rust, we can avoid NonZeroXX and use something better like:
type PositiveU32 = u32[1 ..];