Module legion::serialize [−][src]
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 ComponentTypeId
s
(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. |
DeserializeIntoWorld | Wraps a |
DeserializeNewWorld | Wraps a |
Registry | A world (de)serializer which describes how to (de)serialize the component types in a world. |
SerializableWorld | A serializable representation of a world. |
Enums
UnknownType | An error type describing what to do when a component type is unrecognized. |
Traits
AutoTypeKey | A |
CustomEntitySerializer | Describes a mapping between a runtime |
EntitySerializer | Describes how to serialize and deserialize a runtime |
TypeKey | A (de)serializable type which can represent a component type in a serialized world. |
WorldDeserializer | Describes a type which knows how to deserialize the components in a world. |
WorldSerializer | Describes a type which knows how to deserialize the components in a world. |
Functions
set_entity_serializer | Sets the |
Type Definitions
EntityName | A 16 byte UUID which uniquely identifies an entity. |