Struct ComponentRegistration
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: TypeIdThe TypeId of the component type.
type_name: &'static strA human-readable name for the component (e.g., “Camera”, “Light”).
provenance: ComponentProvenanceWho 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§
impl Collect for ComponentRegistration
Auto Trait Implementations§
impl Freeze for ComponentRegistration
impl RefUnwindSafe for ComponentRegistration
impl Send for ComponentRegistration
impl Sync for ComponentRegistration
impl Unpin for ComponentRegistration
impl UnsafeUnpin for ComponentRegistration
impl UnwindSafe for ComponentRegistration
Blanket Implementations§
§impl<T> AppLifecycle for Twhere
T: ?Sized,
impl<T> AppLifecycle for Twhere
T: ?Sized,
§fn on_start(&mut self, ctx: &mut dyn AppContext)
fn on_start(&mut self, ctx: &mut dyn AppContext)
update. Apps install their theme / fonts here.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.