pub struct Registry<T> where
T: TypeKey, { /* private fields */ }
Expand description
A world (de)serializer which describes how to (de)serialize the component types in a world.
The type parameter T
represents the key used in the serialized output to identify each
component type. The type keys used must uniquely identify each component type, and be stable
between recompiles.
See the legion_typeuuid crate for an example of a type key which is stable between compiles.
Implementations
sourceimpl<T> Registry<T> where
T: TypeKey,
impl<T> Registry<T> where
T: TypeKey,
sourcepub fn on_unknown(&mut self, unknown: UnknownType)
pub fn on_unknown(&mut self, unknown: UnknownType)
Sets the behavior to use when a component type is unknown.
sourcepub fn register<C: Component + Serialize + for<'de> Deserialize<'de>>(
&mut self,
mapped_type_id: T
)
pub fn register<C: Component + Serialize + for<'de> Deserialize<'de>>(
&mut self,
mapped_type_id: T
)
Registers a component type and its key with the registry.
sourcepub fn register_auto_mapped<C: Component + Serialize + for<'de> Deserialize<'de>>(
&mut self
) where
T: AutoTypeKey<C>,
pub fn register_auto_mapped<C: Component + Serialize + for<'de> Deserialize<'de>>(
&mut self
) where
T: AutoTypeKey<C>,
Registers a component type and its key with the registry.
sourcepub fn as_deserialize_into_world<'a, E: EntitySerializer>(
&'a self,
world: &'a mut World,
entity_serializer: &'a E
) -> DeserializeIntoWorld<'a, Self, E>
pub fn as_deserialize_into_world<'a, E: EntitySerializer>(
&'a self,
world: &'a mut World,
entity_serializer: &'a E
) -> DeserializeIntoWorld<'a, Self, E>
Constructs a serde::DeserializeSeed which will deserialize into an existing world.
sourcepub fn as_deserialize<'a, E: EntitySerializer>(
&'a self,
entity_serializer: &'a E
) -> DeserializeNewWorld<'a, Self, E>
pub fn as_deserialize<'a, E: EntitySerializer>(
&'a self,
entity_serializer: &'a E
) -> DeserializeNewWorld<'a, Self, E>
Constructs a serde::DeserializeSeed which will deserialize into a new world.
Trait Implementations
sourceimpl<T> WorldDeserializer for Registry<T> where
T: TypeKey,
impl<T> WorldDeserializer for Registry<T> where
T: TypeKey,
type TypeId = T
type TypeId = T
The stable type ID used to identify each component type in the serialized data.
sourcefn unmap_id(
&self,
type_id: &Self::TypeId
) -> Result<ComponentTypeId, UnknownType>
fn unmap_id(
&self,
type_id: &Self::TypeId
) -> Result<ComponentTypeId, UnknownType>
Converts the serialized type ID into a runtime component type ID.
sourcefn register_component(&self, type_id: Self::TypeId, layout: &mut EntityLayout)
fn register_component(&self, type_id: Self::TypeId, layout: &mut EntityLayout)
Adds the specified component to the given entity layout.
sourcefn deserialize_component_slice<'a, 'de, D: Deserializer<'de>>(
&self,
type_id: ComponentTypeId,
storage: UnknownComponentWriter<'a>,
deserializer: D
) -> Result<(), D::Error>
fn deserialize_component_slice<'a, 'de, D: Deserializer<'de>>(
&self,
type_id: ComponentTypeId,
storage: UnknownComponentWriter<'a>,
deserializer: D
) -> Result<(), D::Error>
Deserializes a slice of components and inserts them into the given storage.
sourcefn deserialize_component<'de, D: Deserializer<'de>>(
&self,
type_id: ComponentTypeId,
deserializer: D
) -> Result<Box<[u8]>, D::Error>
fn deserialize_component<'de, D: Deserializer<'de>>(
&self,
type_id: ComponentTypeId,
deserializer: D
) -> Result<Box<[u8]>, D::Error>
Deserializes a single component and returns it as a boxed u8 slice.
sourceimpl<T> WorldSerializer for Registry<T> where
T: TypeKey,
impl<T> WorldSerializer for Registry<T> where
T: TypeKey,
type TypeId = T
type TypeId = T
The stable type ID used to identify each component type in the serialized data.
sourceunsafe fn serialize_component<Ser: Serializer>(
&self,
ty: ComponentTypeId,
ptr: *const u8,
serializer: Ser
) -> Result<Ser::Ok, Ser::Error>
unsafe fn serialize_component<Ser: Serializer>(
&self,
ty: ComponentTypeId,
ptr: *const u8,
serializer: Ser
) -> Result<Ser::Ok, Ser::Error>
Serializes a single component. Read more
sourcefn map_id(&self, type_id: ComponentTypeId) -> Result<Self::TypeId, UnknownType>
fn map_id(&self, type_id: ComponentTypeId) -> Result<Self::TypeId, UnknownType>
Converts a runtime component type ID into the serialized type ID.
sourceunsafe fn serialize_component_slice<Ser: Serializer>(
&self,
ty: ComponentTypeId,
storage: &dyn UnknownComponentStorage,
archetype: ArchetypeIndex,
serializer: Ser
) -> Result<Ser::Ok, Ser::Error>
unsafe fn serialize_component_slice<Ser: Serializer>(
&self,
ty: ComponentTypeId,
storage: &dyn UnknownComponentStorage,
archetype: ArchetypeIndex,
serializer: Ser
) -> Result<Ser::Ok, Ser::Error>
Serializes a slice of components. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Registry<T> where
T: RefUnwindSafe,
impl<T> Send for Registry<T> where
T: Send,
impl<T> Sync for Registry<T> where
T: Sync,
impl<T> Unpin for Registry<T> where
T: Unpin,
impl<T> UnwindSafe for Registry<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcepub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcepub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcepub fn as_any(&self) -> &(dyn Any + 'static)
pub fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
sourcepub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more