strum icon indicating copy to clipboard operation
strum copied to clipboard

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

Open biryukovmaxim opened this issue 1 year ago • 4 comments

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 avatar Apr 26 '24 12:04 biryukovmaxim

@Peternator7 could you check it out?

biryukovmaxim avatar Apr 30 '24 08:04 biryukovmaxim

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

Peternator7 avatar May 12 '24 22:05 Peternator7

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

Added

biryukovmaxim avatar May 13 '24 08:05 biryukovmaxim

Could someone on the team merge this?

lf94 avatar Aug 22 '24 14:08 lf94