Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NonZeroUsize should implement TryFrom<usize> #73664

Closed
larsluthman opened this issue Jun 23, 2020 · 3 comments
Closed

NonZeroUsize should implement TryFrom<usize> #73664

larsluthman opened this issue Jun 23, 2020 · 3 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@larsluthman
Copy link

std::num::NonZeroUsize does not implement the trait std::convert::TryFrom<usize>, and the same goes for all the other NonZero types - they don't implement TryFrom conversions from their inner type. This seems to be exactly the sort of situation that TryFrom was created for, so they probably should.

The NonZeroUsize::new() method already does something similar by returning None if the value is zero, but having TryFrom would be nice for consistency and for generic code.

@larsluthman larsluthman added the C-bug Category: This is a bug. label Jun 23, 2020
@sfackler
Copy link
Member

#72717

@larsluthman
Copy link
Author

Thanks! I searched the issues before adding this one but didn't think to also search the pull requests. Will do that next time.

@LeSeulArtichaut LeSeulArtichaut added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Jun 24, 2020
@Mark-Simulacrum
Copy link
Member

Closing as I think this is done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants