@@ -52,10 +52,39 @@ fn get_serializable<'a, E: Error>(
52
52
53
53
/// A general purpose serializer for reflected types.
54
54
///
55
- /// The serialized data will take the form of a map containing the following entries:
56
- /// 1. `type`: The _full_ [type path]
57
- /// 2. `value`: The serialized value of the reflected type
55
+ /// This is the serializer counterpart to [`ReflectDeserializer`].
58
56
///
57
+ /// See [`TypedReflectSerializer`] for a serializer that serializes a known type.
58
+ ///
59
+ /// # Output
60
+ ///
61
+ /// This serializer will output a map with a single entry,
62
+ /// where the key is the _full_ [type path] of the reflected type
63
+ /// and the value is the serialized data.
64
+ ///
65
+ /// # Example
66
+ ///
67
+ /// ```
68
+ /// # use bevy_reflect::prelude::*;
69
+ /// # use bevy_reflect::{TypeRegistry, serde::ReflectSerializer};
70
+ /// #[derive(Reflect, PartialEq, Debug)]
71
+ /// #[type_path = "my_crate"]
72
+ /// struct MyStruct {
73
+ /// value: i32
74
+ /// }
75
+ ///
76
+ /// let mut registry = TypeRegistry::default();
77
+ /// registry.register::<MyStruct>();
78
+ ///
79
+ /// let input = MyStruct { value: 123 };
80
+ ///
81
+ /// let reflect_serializer = ReflectSerializer::new(&input, ®istry);
82
+ /// let output = ron::to_string(&reflect_serializer).unwrap();
83
+ ///
84
+ /// assert_eq!(output, r#"{"my_crate::MyStruct":(value:123)}"#);
85
+ /// ```
86
+ ///
87
+ /// [`ReflectDeserializer`]: crate::serde::ReflectDeserializer
59
88
/// [type path]: crate::TypePath::type_path
60
89
pub struct ReflectSerializer < ' a > {
61
90
pub value : & ' a dyn Reflect ,
@@ -97,8 +126,44 @@ impl<'a> Serialize for ReflectSerializer<'a> {
97
126
}
98
127
}
99
128
100
- /// A serializer for reflected types whose type is known and does not require
101
- /// serialization to include other metadata about it.
129
+ /// A serializer for reflected types whose type will be known during deserialization.
130
+ ///
131
+ /// This is the serializer counterpart to [`TypedReflectDeserializer`].
132
+ ///
133
+ /// See [`ReflectSerializer`] for a serializer that serializes an unknown type.
134
+ ///
135
+ /// # Output
136
+ ///
137
+ /// Since the type is expected to be known during deserialization,
138
+ /// this serializer will not output any additional type information,
139
+ /// such as the [type path].
140
+ ///
141
+ /// Instead, it will output just the serialized data.
142
+ ///
143
+ /// # Example
144
+ ///
145
+ /// ```
146
+ /// # use bevy_reflect::prelude::*;
147
+ /// # use bevy_reflect::{TypeRegistry, serde::TypedReflectSerializer};
148
+ /// #[derive(Reflect, PartialEq, Debug)]
149
+ /// #[type_path = "my_crate"]
150
+ /// struct MyStruct {
151
+ /// value: i32
152
+ /// }
153
+ ///
154
+ /// let mut registry = TypeRegistry::default();
155
+ /// registry.register::<MyStruct>();
156
+ ///
157
+ /// let input = MyStruct { value: 123 };
158
+ ///
159
+ /// let reflect_serializer = TypedReflectSerializer::new(&input, ®istry);
160
+ /// let output = ron::to_string(&reflect_serializer).unwrap();
161
+ ///
162
+ /// assert_eq!(output, r#"(value:123)"#);
163
+ /// ```
164
+ ///
165
+ /// [`TypedReflectDeserializer`]: crate::serde::TypedReflectDeserializer
166
+ /// [type path]: crate::TypePath::type_path
102
167
pub struct TypedReflectSerializer < ' a > {
103
168
pub value : & ' a dyn Reflect ,
104
169
pub registry : & ' a TypeRegistry ,
0 commit comments