-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
What problem does this solve or what need does it fill?
Reflection and serialization (specifically, serde serialization) are tightly coupled right now.
For example, Option<T>'s Reflect implementation has a Serialize trait bound.
This can make it challenging to model types that should be reflected but not serialized (e.g. for fancy ECS tricks like trait queries or editor inspection, see #3580). Additionally, this makes relying on bevy_reflect without using serde (either without any serialization or with an alternate backend) effectively impossible.
What solution would you like?
- Lock all of the serialization code behind a
serializefeature flag.serdeshould only be a dependency with theserdeflag enabled. - Modify the
impl_reflect_valuemacro to account for whether or not this feature flag is enabled. - Remove the serialize and deserialize trait bounds on storage types like
OptionandHashSet. We should ensure that these types can still be serialized if and only if the underlying values are serializable. - Remove the
serializemethod onReflect. Instead, create a secondReflectSerializationtrait that handles this, and does not return an option. This method should return aBox<dyn Serializable>, allowing users to implement this trait with their own serialization backend.
Alternatives considered
We could keep serialize as a method on Reflect. This is less useful, as being able to distinguish between serializable reflected objects and non-serializable ones at the type level is very relevant in end-user code. It also prevents us from hiding all of the serialization functionality behind a feature flag.
Additional context
Issue created for @kabergstrom, who wants to avoid serde due to excessive compilation times.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status