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

Add choose_index -- a generalization of choose #105

Merged
merged 1 commit into from
Apr 3, 2022

Conversation

matklad
Copy link
Contributor

@matklad matklad commented Apr 3, 2022

choose comes only in one modality -- selecting a shared reference.
Often one wants an exclusive reference or maybe even to take ownership.

Rather than adding all those flavors, let's expose a function to
generate an index, the caller would then be able to DIY the rest.

Of course, the caller can open-code u.gen_int(0..=array.len() - 1)
themselves, but -1 is annoying, and that'll also panic if the array
turns out to be empty. With choose_index, we can re-use the
EmptyChoice error.

`choose` comes only in one modality -- selecting a shared reference.
Often one wants an exclusive reference or maybe even to take ownership.

Rather than adding all those flavors, let's expose a function to
generate an index, the caller would then be able to DIY the rest.

Of course, the caller can open-code `u.gen_int(0..=array.len() - 1)`
themselves, but `-1` is annoying, and that'll also panic if the array
turns out to be empty. With `choose_index`, we can re-use the
`EmptyChoice` error.
@Manishearth Manishearth merged commit 5934aa1 into rust-fuzz:master Apr 3, 2022
@matklad matklad deleted the choose-index branch April 3, 2022 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants