Skip to content

Commit

Permalink
bevy_reflect: Rename UntypedReflectDeserializer to `ReflectDeserial…
Browse files Browse the repository at this point in the history
…izer` (#12721)

# Objective

We have `ReflectSerializer` and `TypedReflectSerializer`. The former is
the one users will most often use since the latter takes a bit more
effort to deserialize.

However, our deserializers are named `UntypedReflectDeserializer` and
`TypedReflectDeserializer`. There is no obvious indication that
`UntypedReflectDeserializer` must be used with `ReflectSerializer` since
the names don't quite match up.

## Solution

Rename `UntypedReflectDeserializer` back to `ReflectDeserializer`
(initially changed as part of #5723).

Also update the docs for both deserializers (as they were pretty out of
date) and include doc examples.

I also updated the docs for the serializers, too, just so that
everything is consistent.

---

## Changelog

- Renamed `UntypedReflectDeserializer` to `ReflectDeserializer`
- Updated docs for `ReflectDeserializer`, `TypedReflectDeserializer`,
`ReflectSerializer`, and `TypedReflectSerializer`

## Migration Guide

`UntypedReflectDeserializer` has been renamed to `ReflectDeserializer`.
Usages will need to be updated accordingly.

```diff
- let reflect_deserializer = UntypedReflectDeserializer::new(&registry);
+ let reflect_deserializer = ReflectDeserializer::new(&registry);
```
  • Loading branch information
MrGVSV authored Mar 26, 2024
1 parent e6b5f05 commit 0265436
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 109 deletions.
18 changes: 9 additions & 9 deletions crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
//! The way it works is by moving the serialization logic into common serializers and deserializers:
//! * [`ReflectSerializer`]
//! * [`TypedReflectSerializer`]
//! * [`UntypedReflectDeserializer`]
//! * [`ReflectDeserializer`]
//! * [`TypedReflectDeserializer`]
//!
//! All of these structs require a reference to the [registry] so that [type information] can be retrieved,
Expand All @@ -347,7 +347,7 @@
//! and the value is the serialized data.
//! The `TypedReflectSerializer` will simply output the serialized data.
//!
//! The `UntypedReflectDeserializer` can be used to deserialize this map and return a `Box<dyn Reflect>`,
//! The `ReflectDeserializer` can be used to deserialize this map and return a `Box<dyn Reflect>`,
//! where the underlying type will be a dynamic type representing some concrete type (except for value types).
//!
//! Again, it's important to remember that dynamic types may need to be converted to their concrete counterparts
Expand All @@ -357,7 +357,7 @@
//! ```
//! # use serde::de::DeserializeSeed;
//! # use bevy_reflect::{
//! # serde::{ReflectSerializer, UntypedReflectDeserializer},
//! # serde::{ReflectSerializer, ReflectDeserializer},
//! # Reflect, FromReflect, TypeRegistry
//! # };
//! #[derive(Reflect, PartialEq, Debug)]
Expand All @@ -378,7 +378,7 @@
//! let serialized_value: String = ron::to_string(&reflect_serializer).unwrap();
//!
//! // Deserialize
//! let reflect_deserializer = UntypedReflectDeserializer::new(&registry);
//! let reflect_deserializer = ReflectDeserializer::new(&registry);
//! let deserialized_value: Box<dyn Reflect> = reflect_deserializer.deserialize(
//! &mut ron::Deserializer::from_str(&serialized_value).unwrap()
//! ).unwrap();
Expand Down Expand Up @@ -460,7 +460,7 @@
//! [`serde`]: ::serde
//! [`ReflectSerializer`]: serde::ReflectSerializer
//! [`TypedReflectSerializer`]: serde::TypedReflectSerializer
//! [`UntypedReflectDeserializer`]: serde::UntypedReflectDeserializer
//! [`ReflectDeserializer`]: serde::ReflectDeserializer
//! [`TypedReflectDeserializer`]: serde::TypedReflectDeserializer
//! [registry]: TypeRegistry
//! [type information]: TypeInfo
Expand Down Expand Up @@ -610,7 +610,7 @@ mod tests {
use super::prelude::*;
use super::*;
use crate as bevy_reflect;
use crate::serde::{ReflectSerializer, UntypedReflectDeserializer};
use crate::serde::{ReflectDeserializer, ReflectSerializer};
use crate::utility::GenericTypePathCell;

#[test]
Expand Down Expand Up @@ -1223,7 +1223,7 @@ mod tests {
let serialized = to_string_pretty(&serializer, PrettyConfig::default()).unwrap();

let mut deserializer = Deserializer::from_str(&serialized).unwrap();
let reflect_deserializer = UntypedReflectDeserializer::new(&registry);
let reflect_deserializer = ReflectDeserializer::new(&registry);
let value = reflect_deserializer.deserialize(&mut deserializer).unwrap();
let dynamic_struct = value.take::<DynamicStruct>().unwrap();

Expand Down Expand Up @@ -2383,7 +2383,7 @@ bevy_reflect::tests::Test {
registry.register::<Quat>();
registry.register::<f32>();

let de = UntypedReflectDeserializer::new(&registry);
let de = ReflectDeserializer::new(&registry);

let mut deserializer =
Deserializer::from_str(data).expect("Failed to acquire deserializer");
Expand Down Expand Up @@ -2440,7 +2440,7 @@ bevy_reflect::tests::Test {
registry.add_registration(Vec3::get_type_registration());
registry.add_registration(f32::get_type_registration());

let de = UntypedReflectDeserializer::new(&registry);
let de = ReflectDeserializer::new(&registry);

let mut deserializer =
Deserializer::from_str(data).expect("Failed to acquire deserializer");
Expand Down
Loading

0 comments on commit 0265436

Please sign in to comment.