bevy/crates/bevy_reflect/bevy_reflect_derive/src
Jakob Hellermann 218b0fd3b6 bevy_reflect: put serialize into external ReflectSerialize type (#4782)
builds on top of #4780 

# Objective

`Reflect` and `Serialize` are currently very tied together because `Reflect` has a `fn serialize(&self) -> Option<Serializable<'_>>` method. Because of that, we can either implement `Reflect` for types like `Option<T>` with `T: Serialize` and have `fn serialize` be implemented, or without the bound but having `fn serialize` return `None`.

By separating `ReflectSerialize` into a separate type (like how it already is for `ReflectDeserialize`, `ReflectDefault`), we could separately `.register::<Option<T>>()` and `.register_data::<Option<T>, ReflectSerialize>()` only if the type `T: Serialize`.

This PR does not change the registration but allows it to be changed in a future PR.

## Solution

- add the type
```rust
struct ReflectSerialize { .. }
impl<T: Reflect + Serialize> FromType<T> for ReflectSerialize { .. }
```

- remove `#[reflect(Serialize)]` special casing. 

- when serializing reflect value types, look for `ReflectSerialize` in the `TypeRegistry` instead of calling `value.serialize()`
2022-06-20 17:18:58 +00:00
..
container_attributes.rs bevy_reflect: put serialize into external ReflectSerialize type (#4782) 2022-06-20 17:18:58 +00:00
derive_data.rs bevy_reflect_derive: Tidying up the code (#4712) 2022-05-12 19:43:23 +00:00
field_attributes.rs bevy_reflect: Add #[reflect(default)] attribute for FromReflect (#4140) 2022-05-30 19:06:25 +00:00
from_reflect.rs bevy_reflect: Add #[reflect(default)] attribute for FromReflect (#4140) 2022-05-30 19:06:25 +00:00
impls.rs bevy_reflect: put serialize into external ReflectSerialize type (#4782) 2022-06-20 17:18:58 +00:00
lib.rs bevy_reflect: Add #[reflect(default)] attribute for FromReflect (#4140) 2022-05-30 19:06:25 +00:00
reflect_value.rs bevy_reflect_derive: Tidying up the code (#4712) 2022-05-12 19:43:23 +00:00
registration.rs bevy_reflect_derive: Tidying up the code (#4712) 2022-05-12 19:43:23 +00:00
trait_reflection.rs bevy_reflect: Added get_boxed method to reflect_trait (#4120) 2022-05-20 13:31:49 +00:00
type_uuid.rs Clippy improvements (#4665) 2022-05-31 01:38:07 +00:00
utility.rs bevy_reflect_derive: Tidying up the code (#4712) 2022-05-12 19:43:23 +00:00