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>(),
    &registry,
    &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

Contains the canon names of entities.

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

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

A world (de)serializer which describes how to (de)serialize the component types in a world.

A serializable representation of a world.

Enums

An error type describing what to do when a component type is unrecognized.

Traits

A TypeKey which can construct itself for a given type T.

Describes a mapping between a runtime Entity ID and a serialized equivalent.

Describes how to serialize and deserialize a runtime Entity ID.

A (de)serializable type which can represent a component type in a serialized world.

Describes a type which knows how to deserialize the components in a world.

Describes a type which knows how to deserialize the components in a world.

Functions

Sets the EntitySerializer currently being used to serialize or deserialize Entity IDs.

Type Definitions

A 16 byte UUID which uniquely identifies an entity.