bevy_reflect: `#[reflect(skip_serializing)]` doesn't work on enum variant fields
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Reflected enums do not support `SerializationData`. This is because `SerializationData` works for a single set of fields but enums can have multiple (one set per variant).
This means that we `#[reflect(skip_serializing)]` is ignored for a variant's fields. For example, this does nothing:
```rust
#[derive(Reflect)]
enum Foo {
A {
#[reflect(skip_serializing)]
value: i32,
}
}
```
## What solution would you like?
Ideally we should enable this behavior on enums. They should register and store the ignored set per variant. To do so, we probably need to change `SerializationData` into an enum with one variant for structs and another for enums.
Alternatively, we could rethink `SerializationData` and make its data available on the `TypeInfo` itself (or on the individual `NamedField` and `UnnamedField` info structs). The reason we might not want to do this is doing so begins to (1) add bloat to those structs and (2) tightly couple reflect-_related_ logic with reflection itself. It might be okay for just this attribute, but we may want to be cautious of how much we make "intrinsic" to reflection.
## What alternative(s) have you considered?
We could potentially just disallow this behavior. That's definitely not ideal but we could easily add a compile error if this attribute is placed on a variant's field.
Contributor guide
Research direction
Start by tracing SerializationData and reflected enum registration, the reflection entry points named in the issue. Compare how serialization metadata works for structs with the missing per-variant behavior, then evaluate the proposed TypeInfo or field-level alternatives. Done means #[reflect(skip_serializing)] is honored for fields on every reflected enum variant.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100