bevy/crates/bevy_reflect/src
Gino Valente ba3d9b3fb6
bevy_reflect: Refactor serde module (#15107)
# Objective

The `ser` and `de` modules in `bevy_reflect/serde` are very long and
difficult to navigate.

## Solution

Refactor both modules into many smaller modules that each have a single
primary focus (i.e. a `structs` module that only handles struct
serialization/deserialization).

I chose to keep the `ser` and `de` modules separate. We could have
instead broken it up kind (e.g. lists, maps, etc.), but I think this is
a little cleaner. Serialization and deserialization, while related, can
be very different. So keeping them separated makes sense for
organizational purposes.

That being said, if people disagree and think we should structure this a
different way, I am open to changing it.

Note that this PR's changes are mainly structural. There are a few
places I refactored code to reduce duplication and to make things a bit
cleaner, but these are largely cosmetic and shouldn't have any impact on
behavior.

### Other Details

This PR also hides a lot of the internal logic from being exported.
These were originally public, but it's unlikely they really saw any use
outside of these modules. In fact, you don't really gain anything by
using them outside of this module either.

By privatizing these fields and items, we also set ourselves up for more
easily changing internal logic around without involving a breaking
change.

I also chose not to mess around with tests since that would really blow
up the diff haha.

## Testing

You can test locally by running:

```
cargo test --package bevy_reflect --all-features
```

---

## Migration Guide

The fields on `ReflectSerializer` and `TypedReflectSerializer` are now
private. To instantiate, the corresponding constructor must be used:

```rust
// BEFORE
let serializer = ReflectSerializer {
    value: &my_value,
    registry: &type_registry,
};

// AFTER
let serializer = ReflectSerializer::new(&my_value, &type_registry);
```

Additionally, the following types are no longer public:

- `ArraySerializer`
- `EnumSerializer`
- `ListSerializer`
- `MapSerializer`
- `ReflectValueSerializer` (fully removed)
- `StructSerializer`
- `TupleSerializer`
- `TupleStructSerializer`

As well as the following traits:

- `DeserializeValue` (fully removed)
2024-09-09 14:03:42 +00:00
..
enums bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
func bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
impls Reflect SmolStr's De/Serialize implementation (#14982) 2024-09-02 22:35:17 +00:00
path Apply unused_qualifications lint (#14828) 2024-08-21 12:29:33 +00:00
serde bevy_reflect: Refactor serde module (#15107) 2024-09-09 14:03:42 +00:00
array.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
attributes.rs Fix intra-doc links and make CI test them (#14076) 2024-07-11 13:08:31 +00:00
fields.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
from_reflect.rs reflect: implement the unique reflect rfc (#7207) 2024-08-12 17:01:41 +00:00
lib.rs Unify crate-level preludes (#15080) 2024-09-08 17:10:57 +00:00
list.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
map.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
reflect.rs bevy_reflect: Reflect remote types (#6042) 2024-08-12 19:12:53 +00:00
remote.rs bevy_reflect: Reflect remote types (#6042) 2024-08-12 19:12:53 +00:00
set.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
std_traits.rs fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
struct_trait.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
tuple_struct.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
tuple.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
type_info.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
type_path.rs Add on_unimplemented Diagnostics to Most Public Traits (#13347) (#13662) 2024-06-04 00:31:34 +00:00
type_registry.rs reflect: implement the unique reflect rfc (#7207) 2024-08-12 17:01:41 +00:00
utility.rs Split GenericTypeCell::get_or_insert into smaller pieces (#14865) 2024-08-26 18:20:01 +00:00