It should be possible for an integer literal to initialize a NonZeroInt type, like NonZeroUsize. For instance, this should be legal:
struct Settings {
// None means unlimited
max_args: Option<NonZeroUsize>
}
let settings = Settings {
max_args: Some(2),
}
The compiler can easily check whether the literal is zero and fail if it is.
While I know that the NonZero types are "just" regular structs, it seems as though they already have so many special compiler attributes attached to them to ensure that they work with Option correctly that it seems like it wouldn't be much of a stretch to have this one as well (though I'm happy to be corrected there).
It should be possible for an integer literal to initialize a
NonZeroInttype, likeNonZeroUsize. For instance, this should be legal:The compiler can easily check whether the literal is zero and fail if it is.
While I know that the
NonZerotypes are "just" regular structs, it seems as though they already have so many special compiler attributes attached to them to ensure that they work with Option correctly that it seems like it wouldn't be much of a stretch to have this one as well (though I'm happy to be corrected there).