Missing TryFrom<iX> implementation for NonZero<iY>
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Currently, we have the following implementations:
TryFrom<iX>forNonZero<iX>(for i in [i, u] and X in [8, 16, 32, 64, 128, size])TryFrom<NonZero<iX>>forNonZero<jY>(for i, j in [i, u]^2 and X, Y in [8, 16, 32, 64, 128, size]^2 if i != j or X > Y)
However, we do not have
TryFrom<iX>forNonZero<jY>(for i, j in [i, u]^2, X, Y in [8, 16, 32, 64, 128]^2 if i != j or X > Y)
This felt like an oversight to me. I found https://github.com/rust-lang/rust/pull/72712 where it looks like a decision on whether or not those methods should exist was put off. I know I can chain two TryFrom impls together but that feels very unergonomic to me.
In case it matters, my use case is that I get a list of core::time::Duration that I need to store in a list of Option<NonZeroU32> with microsecond precision, but as_micros() returns a u128, so I need to convert it (or return an error if that is not possible).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the existing TryFrom implementations for NonZero integer types and compare their supported signedness and widths with the combinations listed in this issue. Determine whether the missing direct conversions fit the prior discussion in PR 72712, then add coverage for the intended combinations and verify that overflow and zero cases remain handled correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100