rewrite gen_range to take any range type instead of low, high#21
Open
cyrgani wants to merge 1 commit intonot-fl3:masterfrom
Open
rewrite gen_range to take any range type instead of low, high#21cyrgani wants to merge 1 commit intonot-fl3:masterfrom
gen_range to take any range type instead of low, high#21cyrgani wants to merge 1 commit intonot-fl3:masterfrom
Conversation
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 is a breaking change and requires the next released version to be 0.3.0.
This PR rewrites
gen_rangeandgen_range_with_stateto take one argument that is any range type (impl RangeBounds<T>) instead of two argumentslowandhigh. It also adds an example to show that all core range types are supported.This has several advantages:
u8", sincequad_rand::gen_range(0, 255)is never going to return 255, as this program demonstrates:With this PR, one would simply write
quad_rand::gen_range(0..=255)(or justquad_rand::gen_range(..)as long as the type of the range elements can be inferred) and get anu8that can be 255 too.2. It is currently not always clear to a user whether the
highargument is inclusive or exclusive, which has caused confusion and bugs in the past (e.g. #13). The new API solves that problem by making inclusive ranges explicitlylow..=highand exclusive oneslow..high.It is also more consistent with other ecosystem crates like
rand.Fixes not-fl3/macroquad#403.