You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Surprisingly, it seems Rust does not yet have a robust story for this. variant_count is still not stabilized and the latest comments in the issue seem to indicate going in a different direction with magic constants like MyEnum::enum#VARIANT_COUNT .
cdleary
added
the
dslx
DSLX (domain specific language) implementation / front-end
label
Nov 14, 2024
I think this also gets more urgent if we had iota-assigning enums -- right now you have to name all the values by hand so making COUNT with the underlying type is comparatively not so burdensome. I'm not sure if we have an issue for that? We do have #1306 for getting proper sum types.
What's hard to do? (limit 100 words)
Similar to
u32::MAX
, it would be nice to have a way to get the number of elements in an enum. Similar to rust's std::mem::variant_count.Current best alternative workaround (limit 100 words)
Make a const yourself and hope you keep it up to date.
Your view of the "best case XLS enhancement" (limit 100 words)
A builtin
std::variant_count!<>
or a colon-ref (likeu32::MAX
), e.g. EnumType::NUM_VARIANTS.The text was updated successfully, but these errors were encountered: