Skip to content

feat: Add TryFromIntError::kind#153178

Draft
sorairolake wants to merge 1 commit intorust-lang:mainfrom
sorairolake:feature/try-from-int-error-kind
Draft

feat: Add TryFromIntError::kind#153178
sorairolake wants to merge 1 commit intorust-lang:mainfrom
sorairolake:feature/try-from-int-error-kind

Conversation

@sorairolake
Copy link
Contributor

This pull request adds kind method to TryFromIntError, which outputs the detailed cause of converting an integer failing.

This is primarily intended for use in cases where there are multiple causes for failure, such as converting from a large signed integer type to a small signed integer type.

At the moment, this method returns &IntErrorKind. This type implements the Copy trait and could return IntErrorKind, but returns a reference to align with the behavior of ParseIntError::kind. If it is not necessary to align the behavior of TryFromIntError::kind with ParseIntError::kind, I'll change this method to return IntErrorKind.

Before this pull request, IntErrorKind was only used by ParseIntError, but I changed it to be used by TryFromIntError as well, so I updated IntErrorKind's documentation.

impl TryFrom<usize> for Alignment returns TryFromIntError as an error if the given value is not a power of two. However, IntErrorKind does not have a variant that represents this. So I added the variant NotAPowerOfTwo to represent this.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 27, 2026
@sorairolake
Copy link
Contributor Author

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 27, 2026
@sorairolake sorairolake force-pushed the feature/try-from-int-error-kind branch from d40d08a to 38cf8bf Compare February 27, 2026 12:31
@sorairolake sorairolake force-pushed the feature/try-from-int-error-kind branch from 38cf8bf to 20c70f9 Compare February 27, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants