add infallible conversions between different bit sizes#23
Merged
jhpratt merged 5 commits intojhpratt:mainfrom Aug 18, 2025
Merged
add infallible conversions between different bit sizes#23jhpratt merged 5 commits intojhpratt:mainfrom
jhpratt merged 5 commits intojhpratt:mainfrom
Conversation
Owner
|
I'll certainly have some follow-up work, but in general this looks great. Ordinarily I would request that you not bump the MSRV, but I intended to do that soon anyways given that I have also bumped it for While not technically a major change, I'll likely release this in part of 0.5 soon; I want to wrap up some other work before a release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows you to convert, for example, a RangedI8<-100, 100> to a RangedI32<-100, 100> without having to cast the value manually and avoiding unnecessary range checks.
The macro checks that the source ranged type's range fits within the destination ranged type's range, and it uses the larger of the two types for the comparison to ensure that the conversion is valid. It also asserts that the source and destination ranges are valid at compile time.
Updated MSRV to 1.79 (june 2024) to use const blocks for asserts that are much more readable instead of creating new assert trait.
This change doesn't try to convert between signed and unsigned types.