GeminiLab / enumerable

Enumerate all possible values of a type in Rust.
https://docs.rs/enumerable
MIT License
1 stars 1 forks source link

Enumerable::ENUMERABLE_SIZE #17

Closed stepancheg closed 2 months ago

stepancheg commented 2 months ago

Associated constant for the number of values in this enumerable. If the number exceeds usize::MAX, accessing the constant fails at compile time.

This is useful to create a compact storage to map all the values:

let mut data: [None; MyEnum::ENUMERABLE_SIZE];

I chose name ENUMERABLE_SIZE not SIZE to avoid confusion with possible other meaning of SIZE (for example, foru32`SIZE could also mean size in bytes).

Follow-up to this PR would be implementing:

aarkegz commented 2 months ago

Would you please create an issue about these features? I think that these features given/proposed in this PR are very useful and sometimes critical, but I have several questions.

Thank you for your contribution! Very happy to see you in this repo again.

aarkegz commented 2 months ago

I've created issue #26 for this PR.

For Enumerable::enumerable_index and Enumerable::enumerable_from_index, I misunderstood their purpose in my last comment. I'll discuss them in #27.