Commit c040d76
Enum support in SettingsGroup derive macro, implemented key attribute (#23719)
# Objective
Implements part of #23302
Fixes: #23722
For background on bevy settings see the initial PR:
#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>1 parent d15ada7 commit c040d76
3 files changed
Lines changed: 256 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
| 739 | + | |
739 | 740 | | |
740 | 741 | | |
741 | 742 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
524 | 524 | | |
525 | 525 | | |
526 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
527 | 531 | | |
528 | 532 | | |
529 | 533 | | |
| |||
560 | 564 | | |
561 | 565 | | |
562 | 566 | | |
563 | | - | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
564 | 608 | | |
565 | 609 | | |
566 | 610 | | |
567 | 611 | | |
568 | 612 | | |
569 | 613 | | |
570 | | - | |
571 | | - | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
572 | 619 | | |
573 | 620 | | |
574 | 621 | | |
| |||
580 | 627 | | |
581 | 628 | | |
582 | 629 | | |
583 | | - | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
584 | 636 | | |
585 | 637 | | |
586 | 638 | | |
| |||
594 | 646 | | |
595 | 647 | | |
596 | 648 | | |
597 | | - | |
| 649 | + | |
598 | 650 | | |
599 | 651 | | |
600 | | - | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
601 | 694 | | |
602 | 695 | | |
603 | 696 | | |
604 | 697 | | |
605 | 698 | | |
606 | | - | |
| 699 | + | |
607 | 700 | | |
608 | 701 | | |
609 | 702 | | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
610 | 708 | | |
611 | 709 | | |
612 | 710 | | |
| |||
0 commit comments