bevy_reflect::serde

Trait DeserializeWithRegistry

Source
pub trait DeserializeWithRegistry<'de>: PartialReflect + Sized {
    // Required method
    fn deserialize<D>(
        deserializer: D,
        registry: &TypeRegistry,
    ) -> Result<Self, D::Error>
       where D: Deserializer<'de>;
}
Expand description

Trait used to provide finer control when deserializing a reflected type with one of the reflection deserializers.

This trait is the reflection equivalent of serde’s Deserialize trait. The main difference is that this trait provides access to the TypeRegistry, which means that we can use the registry and all its stored type information to deserialize our type.

This can be useful when writing a custom reflection deserializer where we may want to handle parts of the deserialization process, but temporarily pass control to the standard reflection deserializer for other parts.

For the serialization equivalent of this trait, see SerializeWithRegistry.

§Rationale

Without this trait and its associated type data, such a deserializer would have to write out all of the deserialization logic itself, possibly including unnecessary code duplication and trivial implementations.

This is because a normal Deserialize implementation has no knowledge of the TypeRegistry and therefore cannot create a reflection-based deserializer for nested items.

§Implementors

In order for this to work with the reflection deserializers like TypedReflectDeserializer and ReflectDeserializer, implementors should be sure to register the ReflectDeserializeWithRegistry type data. This can be done via the registry or by adding #[reflect(DeserializeWithRegistry)] to the type definition.

Required Methods§

Source

fn deserialize<D>( deserializer: D, registry: &TypeRegistry, ) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§