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

Add support for `const_into_str` attribute to enable static string conversions in const contexts #353

Closed biryukovmaxim closed 4 days ago

biryukovmaxim commented 7 months ago

This pull request introduces the const_into_str attribute to the strum macros, enabling enums to be converted into static strings in const contexts. This feature is particularly useful when working with compile-time string manipulations, such as those required by concatcp.

Key Changes:

  1. Addition of const_into_str keyword in enum metadata processing.
  2. Conditional generation of a const fn into_str() method for enums marked with const_into_str.
  3. Adjustment in the generation of the From trait to utilize into_str() when const_into_str is enabled.

The implementation ensures that existing functionality is preserved and provides users with the option to opt into this new feature as needed. This feature could be especially beneficial for users needing efficient, compile-time safe string operations involving enums.

Please review the changes and let me know if there are any modifications or improvements required.

resolves #352

biryukovmaxim commented 7 months ago

@Peternator7 could you check it out?

Peternator7 commented 6 months ago

Seems reasonable to me, could you add a test case?

biryukovmaxim commented 6 months ago

Seems reasonable to me, could you add a test case?

Added

lf94 commented 3 months ago

Could someone on the team merge this?

biryukovmaxim commented 1 month ago

@Peternator7 could you take a look?