Skip to content

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

Merged
alice-i-cecile merged 16 commits intobevyengine:mainfrom
mpowell90:feat/extend-settings-group
Apr 13, 2026
Merged

Enum support in SettingsGroup derive macro, implemented key attribute#23719
alice-i-cecile merged 16 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!

Comment thread crates/bevy_ecs/macros/src/lib.rs Outdated
@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
Comment thread crates/bevy_settings/src/lib.rs Outdated
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!

Comment thread crates/bevy_settings/src/lib.rs Outdated
Comment thread crates/bevy_settings/src/lib.rs Outdated
Comment thread crates/bevy_settings/src/lib.rs Outdated
Comment thread crates/bevy_settings/src/lib.rs Outdated
Comment thread crates/bevy_settings/src/lib.rs Outdated
Comment thread crates/bevy_settings/src/lib.rs
Comment thread crates/bevy_settings/src/lib.rs Outdated
@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 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
@kfc35 kfc35 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Apr 10, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 12, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 12, 2026
@kfc35
Copy link
Copy Markdown
Contributor

kfc35 commented Apr 12, 2026

The wasm build failing is unrelated to the PR, but is a legitimate issue that needs to be resolved before CI can pass (probably should be a separate PR)

Copied from the logs for convenience:

error[E0432]: unresolved import `crate::prefs_file`
 --> crates/bevy_settings/src/store_wasm.rs:1:12
  |
1 | use crate::prefs_file::serialize_table;
  |            ^^^^^^^^^^ could not find `prefs_file` in the crate root

error[E0432]: unresolved imports `crate::prefs`, `crate::PreferencesFile`, `crate::PreferencesFileContent`
 --> crates/bevy_settings/src/store_wasm.rs:2:13
  |
2 | use crate::{prefs::PreferencesStore, PreferencesFile, PreferencesFileContent};
  |             ^^^^^                    ^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^ no `PreferencesFileContent` in the root
  |             |                        |
  |             |                        no `PreferencesFile` in the root
  |             could not find `prefs` in the crate root
  |
help: a similar name exists in the module
  |
2 - use crate::{prefs::PreferencesStore, PreferencesFile, PreferencesFileContent};
2 + use crate::{prefs::PreferencesStore, PreferencesStore, PreferencesFileContent};
  |
help: a similar name exists in the module
  |
2 - use crate::{prefs::PreferencesStore, PreferencesFile, PreferencesFileContent};
2 + use crate::{prefs::PreferencesStore, PreferencesFile, PreferenceFileManifest};
  |

For more information about this error, try `rustc --explain E0432`.
error: could not compile `bevy_settings` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
Error: Process completed with exit code 101.

@kfc35 kfc35 added S-Blocked This cannot move forward until something else changes and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Apr 12, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 13, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 13, 2026
github-merge-queue bot pushed a commit that referenced this pull request Apr 13, 2026
…ures (#23779)

# Objective

- Unblock #23719 - The PR revealed that wasm builds are currently broken
for `bevy_settings` when trying to merge to main.
- On main, if you try to build an example that requires `bevy_settings`
for wasm targets, it fails with the same compilation error (i.e. `cargo
build --release --example persisting_preferences --target
wasm32-unknown-unknown --features=“bevy_settings”`)

## Solution

- Fix up `store_wasm.rs`. The function signatures should match those in
`store_fs.rs`, and remove any references that do not exist.

## Testing

- With the `Cargo.toml` change from #23719, was able to build the wasm
target described in Objective successfully. Then, prepared the wasm
target and served it locally following the examples/README.md
directions. The example works as expected for web interactions.
@kfc35
Copy link
Copy Markdown
Contributor

kfc35 commented Apr 13, 2026

Now that #23779 is merged, I think this just needs main merged into it, and then it should pass CI

@kfc35 kfc35 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Blocked This cannot move forward until something else changes labels Apr 13, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 13, 2026
@alice-i-cecile alice-i-cecile removed this pull request from the merge queue due to a manual request Apr 13, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 13, 2026
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Apr 13, 2026
Merged via the queue into bevyengine:main with commit c040d76 Apr 13, 2026
2 checks passed
@mpowell90 mpowell90 deleted the feat/extend-settings-group branch April 13, 2026 09:18
mate-h pushed a commit to mate-h/bevy that referenced this pull request Apr 14, 2026
…ures (bevyengine#23779)

# Objective

- Unblock bevyengine#23719 - The PR revealed that wasm builds are currently broken
for `bevy_settings` when trying to merge to main.
- On main, if you try to build an example that requires `bevy_settings`
for wasm targets, it fails with the same compilation error (i.e. `cargo
build --release --example persisting_preferences --target
wasm32-unknown-unknown --features=“bevy_settings”`)

## Solution

- Fix up `store_wasm.rs`. The function signatures should match those in
`store_fs.rs`, and remove any references that do not exist.

## Testing

- With the `Cargo.toml` change from bevyengine#23719, was able to build the wasm
target described in Objective successfully. Then, prepared the wasm
target and served it locally following the examples/README.md
directions. The example works as expected for web interactions.
mate-h pushed a commit to mate-h/bevy that referenced this pull request Apr 14, 2026
…bevyengine#23719)

# Objective

Implements part of bevyengine#23302

Fixes: bevyengine#23722

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

## Solution

Supports `unit-like` Enum resources:
```rust
#[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:
```toml
[counter_refresh_rate_settings]
counter_refresh_rate_settings = "Slow"
```

Setting the `group` attribute works the same as structs:
```rust
#[settings_group(group = "counter_settings")]
```
Results in:
```toml
[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:
```rust
#[settings_group(key = "refresh_rate")]
```
Results in:
```toml
[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.

---------

Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
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-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#[derive(SettingsGroup)] is unhygienic

5 participants