Expand description
Serde (de)serialization of worlds.
As component types are not known at compile time, the world must be provided with the
means to serialize each component. This is provided by the WorldSerializer implementation.
This implementation also describes how ComponentTypeIds
(which are not stable between compiles) are mapped to stable type identifiers. Components
that are not known to the serializer will be omitted from the serialized output.
The Registry provides a WorldSerializer implementation suitable for most situations.
Serializing all entities with a Position component to JSON.
// create a registry which uses strings as the external type ID
let mut registry = Registry::<String>::default();
registry.register::<Position>("position".to_string());
registry.register::<f32>("f32".to_string());
registry.register::<bool>("bool".to_string());
// serialize entities with the `Position` component
let entity_serializer = Canon::default();
let json = serde_json::to_value(&world.as_serializable(
component::<Position>(),
®istry,
&entity_serializer,
))
.unwrap();
println!("{:#}", json);
// registries are also serde deserializers
use serde::de::DeserializeSeed;
let world: World = registry
.as_deserialize(&entity_serializer)
.deserialize(json)
.unwrap();Structs§
- Canon
- Contains the canon names of entities.
- Deserialize
Into World - Wraps a
WorldDeserializerand a world and implementsserde::DeserializeSeedfor deserializing into the world. - Deserialize
NewWorld - Wraps a
WorldDeserializerand a world and implementsserde::DeserializeSeedfor deserializing into a new world. - Registry
- A world (de)serializer which describes how to (de)serialize the component types in a world.
- Serializable
World - A serializable representation of a world.
Enums§
- Unknown
Type - An error type describing what to do when a component type is unrecognized.
Traits§
- Auto
Type Key - A
TypeKeywhich can construct itself for a given type T. - Custom
Entity Serializer - Describes a mapping between a runtime
EntityID and a serialized equivalent. - Entity
Serializer - Describes how to serialize and deserialize a runtime
EntityID. - TypeKey
- A (de)serializable type which can represent a component type in a serialized world.
- World
Deserializer - Describes a type which knows how to deserialize the components in a world.
- World
Serializer - Describes a type which knows how to deserialize the components in a world.
Functions§
- set_
entity_ serializer - Sets the
EntitySerializercurrently being used to serialize or deserializeEntityIDs.
Type Aliases§
- Entity
Name - A 16 byte UUID which uniquely identifies an entity.