Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

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

Closed

Description

@AdrienPensart

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.

Activity

  1. TheIronBorn commented on Jan 17, 2024

    @TheIronBorn
    Contributor

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

  2. dhardy commented on Jan 18, 2024

    @dhardy
    Member

    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?

  3. AdrienPensart commented on Jan 18, 2024

    @AdrienPensart
    Author

    Yes only small usize values.

  4. dhardy commented on Jan 19, 2024

    @dhardy
    Member

    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?

  5. AdrienPensart commented on Jan 19, 2024

    @AdrienPensart
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions