Elevate `NonZero*` types to true primitive integer types?

I would definitely prefer a generic Checked ala the one the checked crate provides to the current approach of checked_*, much like the Wrapping type provides a more ergonomic alternative to the wrapping_* methods.

That makes it possible to use core::ops::{Add, Sub, Mul, Div} which also enables polymorphism with respect to the arguments.

Since that doesn't exist though, and NonZeroU* has some of the checked_* methods, filling out the rest makes sense for consistency's sake.

I'm not sure how the type signature would differ other than the rhs operand, which is the u* type mapping to the NonZeroU*.

This gets into one of those reasons I want the full solution to the problem instead. Because arguably NonZeroUN::checked_add could take both uN and NonZeroUN as the RHS. But is it worth doing that? Probably not, because it means another trait (even if hidden). And it'd mean that uN::checked_add should arguably also take NonZeroUN...

If we just had an Integer<MIN, MAX> type, we could avoid all of these questions and problems.

4 Likes

Likewise, if there were Checked<NonZeroU32>, it could have multiple Add/Sub impls for both Self and u32.

But Checked doesn't exist yet either.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.