[][src]Module legion::serialize

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 json = serde_json::to_value(&world.as_serializable(component::<Position>(), &registry)).unwrap();
println!("{:#}", json);

// registries are also serde deserializers
use serde::de::DeserializeSeed;
let world: World = registry.as_deserialize().deserialize(json).unwrap();

Structs

Canon

Contains the canon names of entities.

DeserializeIntoWorld

Wraps a WorldDeserializer and a world and implements serde::DeserializeSeed for deserializing into the world.

DeserializeNewWorld

Wraps a WorldDeserializer and a universe and implements serde::DeserializeSeed for deserializing into a new world.

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 TypeKey which can construct itself for a given type T.

EntitySerializer

Describes how to serialize and deserialize a runtime Entity ID.

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.

Type Definitions

EntityName

A 16 byte UUID which uniquely identifies an entity.