1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//! 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](trait.WorldSerializer.html) implementation. This implementation //! also describes how [ComponentTypeIDs](../storage/struct.ComponentTypeId.html) (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](struct.Registry.html) provides a //! [WorldSerializer](trait.WorldSerializer.html) implementation suitable for most //! situations. //! //! Serializing all entities with a `Position` component to JSON. //! ``` //! # use legion::*; //! # let world = World::default(); //! # #[derive(serde::Serialize, serde::Deserialize)] //! # struct Position; //! // 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>(), ®istry)).unwrap(); //! println!("{:#}", json); //! //! // registries are also serde deserializers //! use serde::de::DeserializeSeed; //! let world: World = registry.as_deserialize().deserialize(json).unwrap(); //! ``` pub use crate::internals::serialize::{ de::WorldDeserializer, id::{Canon, EntityName, EntitySerializer}, ser::{SerializableWorld, WorldSerializer}, AutoTypeKey, DeserializeIntoWorld, DeserializeNewWorld, Registry, TypeKey, UnknownType, }; #[cfg(feature = "type-uuid")] pub use crate::internals::serialize::SerializableTypeUuid;