Skip to main content

ComponentRegistration

Struct ComponentRegistration 

Source
pub struct ComponentRegistration {
    pub type_id: TypeId,
    pub type_name: &'static str,
    pub provenance: ComponentProvenance,
    pub serialize_recipe: fn(&World, EntityId) -> Option<Vec<u8>>,
    pub deserialize_recipe: fn(&mut World, EntityId, &[u8]) -> Result<(), String>,
    pub create_default: fn(&mut World, EntityId) -> Result<(), String>,
    pub to_json: fn(&World, EntityId) -> Option<Value>,
    pub from_json: fn(&mut World, EntityId, &Value) -> Result<(), String>,
    pub remove: fn(&mut World, EntityId) -> Result<(), String>,
}
Expand description

Registration entry for a serializable component type.

Each component that derives Component submits an entry via inventory::submit! (generated by the derive macro). The serialization strategies use these registrations to handle all component types automatically.

The two *_recipe functions are the bincode round-trip used by the scene file format ([super::recipe_strategy]). The two *_json functions are the parallel serde-JSON round-trip used by the editor inspector to display and (eventually) edit components without per-type code. Both pairs go through the same auto-generated Serializable<Type> mirror struct; the JSON path simply picks a different encoding.

Fields§

§type_id: TypeId

The TypeId of the component type.

§type_name: &'static str

A human-readable name for the component (e.g., “Camera”, “Light”).

§provenance: ComponentProvenance

Who writes this component — see ComponentProvenance.

Lets any consumer ask “is this the author’s data, or the engine’s?” instead of keeping its own hand-maintained list of type names. The editor’s “Add Component” menu and duplicate_entity both read it, so components declared outside this crate are handled correctly too.

§serialize_recipe: fn(&World, EntityId) -> Option<Vec<u8>>

Serializes the component from the world into a Recipe command’s component_data bytes. Returns None if the entity doesn’t have this component.

§deserialize_recipe: fn(&mut World, EntityId, &[u8]) -> Result<(), String>

Deserializes a Recipe command’s component_data bytes and adds the component to the entity.

§create_default: fn(&mut World, EntityId) -> Result<(), String>

Creates a default instance of this component and adds it to the entity. Used by the editor’s “Add Component” UI.

§to_json: fn(&World, EntityId) -> Option<Value>

Returns a JSON view of the component on entity, or None if the entity doesn’t have it. The conversion goes through the generated Serializable<Type> mirror, so any field tagged #[component(skip)] is omitted (same as the scene-recipe path).

§from_json: fn(&mut World, EntityId, &Value) -> Result<(), String>

Applies a JSON value back to the component on entity. Used by the editor inspector to commit field edits without per-type code. Implementations should be tolerant of partial updates by deserialising against the full mirror struct first.

§remove: fn(&mut World, EntityId) -> Result<(), String>

Removes the component (and any siblings in the same SemanticDomain) from entity. Used by the editor inspector’s per-card delete button to drop a component by type_name lookup.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AppLifecycle for T
where T: ?Sized,

§

fn on_start(&mut self, ctx: &mut dyn AppContext)

Called once after the backend is up but before the first update. Apps install their theme / fonts here.
§

fn on_exit(&mut self)

Called once when the window is closing. Persist state here.
§

impl<T> AsAny for T
where T: Any,

§

fn as_any(&self) -> &(dyn Any + 'static)

Returns a reference to the inner value as &dyn Any.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.