Skip to content

Enum support in SettingsGroup derive macro, implemented key attribute#23719

Open
mpowell90 wants to merge 15 commits intobevyengine:mainfrom
mpowell90:feat/extend-settings-group
Open

Enum support in SettingsGroup derive macro, implemented key attribute#23719
mpowell90 wants to merge 15 commits intobevyengine:mainfrom
mpowell90:feat/extend-settings-group

Conversation

@mpowell90
Copy link
Copy Markdown
Contributor

@mpowell90 mpowell90 commented Apr 8, 2026

Objective

Implements part of #23302

Fixes: #23722

For background on bevy settings see the initial PR:
#23034

Solution

Supports unit-like Enum resources:

#[derive(Resource, SettingsGroup, Reflect, Debug, Default)]
#[reflect(Resource, SettingsGroup, Default)]
enum CounterRefreshRateSettings {
    #[default]
    Slow,
    Fast,
}

Assuming the above is initialised as CounterRefreshRateSettings::Slow, results in:

[counter_refresh_rate_settings]
counter_refresh_rate_settings = "Slow"

Setting the group attribute works the same as structs:

#[settings_group(group = "counter_settings")]

Results in:

[counter_settings]
counter_refresh_rate_settings = "Slow"

This PR adds a key attribute which can only be used on enums (for now), otherwise a compile-time error is thrown:

#[settings_group(key = "refresh_rate")]

Results in:

[counter_refresh_rate_settings]
refresh_rate = "Slow"

Testing

  • Added tests that checks merging enums into groups and round trip serialisation.
  • Added a "cheat sheet" for the derive syntax, immitating other derive macros in the file.

@alice-i-cecile alice-i-cecile requested a review from viridia April 8, 2026 16:42
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Dev-Tools Tools used to debug Bevy applications. labels Apr 8, 2026
@alice-i-cecile alice-i-cecile added this to the 0.19 milestone Apr 8, 2026
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-23719

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

Copy link
Copy Markdown
Contributor

@viridia viridia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-23719

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@mpowell90 mpowell90 force-pushed the feat/extend-settings-group branch from 24abb12 to 6b56f1f Compare April 8, 2026 20:11
@mpowell90
Copy link
Copy Markdown
Contributor Author

FAO reviewers: i've added the fix for #23722 to this PR as it touches the same code. I can split out into a separate PR if preferred.

@kfc35 kfc35 self-requested a review April 9, 2026 14:27
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some doc refinements and some code clean-ups that I’d like to see get done (specifically that removal of the redundant code block)

Also @DavidCrossman ’s comment is valid

Feel free to re-request after you’ve addressed everything!

@kfc35 kfc35 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Macros Code that generates Rust code and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 9, 2026
mpowell90 and others added 3 commits April 10, 2026 11:35
Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
@mpowell90 mpowell90 force-pushed the feat/extend-settings-group branch from 39e74ca to 0606b3d Compare April 10, 2026 10:38
@mpowell90 mpowell90 requested a review from kfc35 April 10, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Dev-Tools Tools used to debug Bevy applications. C-Feature A new feature, making something new possible D-Macros Code that generates Rust code D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[derive(SettingsGroup)] is unhygienic

5 participants