Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 152 forks source link

Support for const_into_str to Enable Static String Conversion in Const Context #352

Closed biryukovmaxim closed 4 days ago

biryukovmaxim commented 7 months ago

Currently, the strum library does not support converting enum variants into static strings within a const context. This limitation arises because the library uses the From trait, which cannot have const methods, even in nightly Rust. This issue becomes particularly significant when attempting to use concatcp to concatenate two static strings in a const context.

To address this limitation, I propose the addition of a new enum meta attribute, const_into_str. This attribute would enable generating an additional public const function for enums, allowing conversion to static strings in a const context.

This enhancement would greatly improve strum's functionality by allowing more flexible and performant use of enums in constant expressions. I have prepared an implementation and will submit a pull request for review.

lf94 commented 3 months ago

I hit this today. I would love if someone did this.