Missing TryFrom<NonZeroFoo> for NonZeroBar #77258
Labels
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
TryFrom<T>
is implemented for typeU
for a lot of different integer combinations (e.g.TryFrom<u128> for u64
). However the correspondingNonZero
variants are not. This seems like an omission: I would expectTryFrom<NonZeroU128> for NonZeroU64
. The alternative is to convert to au128
first, throwing away the knowledge that the value is nonzero, then try to convert it to au64
, then try to convert it to aNonZeroU64
knowing that the latter conversion cannot fail (one is then faced with the choice to either use anunsafe
call tonew_unchecked
, or a potentially unnecessarily slow call tonew
even though you know the zero check is pointless because the value came from aNonZeroU128
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.
The text was updated successfully, but these errors were encountered: