Description
TryFrom<T>
is implemented for type U
for a lot of different integer combinations (e.g. TryFrom<u128> for u64
). However the corresponding NonZero
variants are not. This seems like an omission: I would expect TryFrom<NonZeroU128> for NonZeroU64
. The alternative is to convert to a u128
first, throwing away the knowledge that the value is nonzero, then try to convert it to a u64
, then try to convert it to a NonZeroU64
knowing that the latter conversion cannot fail (one is then faced with the choice to either use an unsafe
call to new_unchecked
, or a potentially unnecessarily slow call to new
even though you know the zero check is pointless because the value came from a NonZeroU128
to start with and therefore cannot possibly be zero).
I saw #72712 which is related, but I thought this was a somewhat separate issue because #72712 talks about conversions from primitives to nonzeroes of different widths, while I am interested in conversions between nonzeroes of different widths—for which infallible cases already exist (e.g. From<NonZeroU32> for NonZeroU64
), only the fallible ones are missing.
A bug ticket might not be quite the right forum for this; if that is the case, my apologies.