Skip to content

Commit a9ca6fb

Browse files
committed
Add docs
1 parent 904a41a commit a9ca6fb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/bevy_reflect/src/serde/ser/serializer.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ use serde::{ser::SerializeMap, Serialize, Serializer};
2525
/// serializer and write into the serializer (successfully or not), or return
2626
/// ownership of the serializer back, and continue with the default logic.
2727
///
28+
/// # Compared to [`SerializeWithRegistry`]
29+
///
30+
/// [`SerializeWithRegistry`] allows you to define how your type will be
31+
/// serialized by a [`TypedReflectSerializer`], given the extra context of the
32+
/// [`TypeRegistry`]. If your type can be serialized entirely using that, then
33+
/// you should prefer implementing that trait instead of using a processor.
34+
///
35+
/// However, you may need more context-dependent data which is only present in
36+
/// the scope where you create the [`TypedReflectSerializer`]. For example, if
37+
/// you need to use a reference to a value while serializing, then there is no
38+
/// way to do this with [`SerializeWithRegistry`] as you can't pass that
39+
/// reference into anywhere. This is where a processor is useful, as the
40+
/// processor can capture local variables.
41+
///
42+
/// A [`ReflectSerializerProcessor`] always takes priority over a
43+
/// [`SerializeWithRegistry`] implementation, so this is also useful for
44+
/// overriding serialization behavior if you need to do something custom.
45+
///
2846
/// # Examples
2947
///
3048
/// Serializing a reflected value when saving an asset to disk, and replacing
@@ -114,6 +132,7 @@ use serde::{ser::SerializeMap, Serialize, Serializer};
114132
/// ```
115133
///
116134
/// [`try_serialize`]: Self::try_serialize
135+
/// [`SerializeWithRegistry`]: crate::serde::SerializeWithRegistry
117136
pub trait ReflectSerializerProcessor {
118137
/// Attempts to serialize the value which a [`TypedReflectSerializer`] is
119138
/// currently looking at.

0 commit comments

Comments
 (0)