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

Make rand::seq::gen_index public ? #1373

Closed
AdrienPensart opened this issue Jan 17, 2024 · 5 comments
Closed

Make rand::seq::gen_index public ? #1373

AdrienPensart opened this issue Jan 17, 2024 · 5 comments

Comments

@AdrienPensart
Copy link

AdrienPensart commented Jan 17, 2024

Hello,

in order to choose a random variant in an enum (with help of Peternator7/strum#297), I would like to use rand::seq::gen_index as index, as it would suppress the need for Option, Iterator, etc.

But it is not marked public.

Would it be possible ? I could just copy/paste it but maybe others need it.

@TheIronBorn
Copy link
Collaborator

What does gen_index provide for you that gen_range doesn't?

@dhardy
Copy link
Member

dhardy commented Jan 18, 2024

We could, though it's not much code to copy+paste. Specifically for enum variants, you are surely never going to be sampling larger than u32::MAX anyway?

@AdrienPensart
Copy link
Author

Yes only small usize values.

@dhardy
Copy link
Member

dhardy commented Jan 19, 2024

So why not copy but simplify to only the 32-bit path?

Actually, can't you determine the number of variants and select an appropriate method at compile time?

@AdrienPensart
Copy link
Author

I copy/pasted the function, thanks!

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

No branches or pull requests

3 participants