Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

biryukovmaxim
Copy link

@biryukovmaxim biryukovmaxim commented Apr 26, 2024

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
Copy link
Author

@Peternator7 could you check it out?

@Peternator7
Copy link
Owner

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

@biryukovmaxim
Copy link
Author

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

Added

@lf94
Copy link

lf94 commented Aug 22, 2024

Could someone on the team merge this?

@biryukovmaxim
Copy link
Author

@Peternator7 could you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for const_into_str to Enable Static String Conversion in Const Context
3 participants