pub trait Component:
Clone
+ 'static
+ Send
+ Sync {
// Provided methods
fn make_column() -> Box<dyn AnyVec>
where Self: Sized { ... }
fn push_into_column(self, column: &mut dyn AnyVec)
where Self: Sized { ... }
fn copy_row_between(src: &dyn AnyVec, src_row: usize, dst: &mut dyn AnyVec)
where Self: Sized { ... }
fn clone_from_column(column: &dyn AnyVec, row: usize) -> Self
where Self: Sized { ... }
fn set_in_column(self, column: &mut dyn AnyVec, row: usize)
where Self: Sized { ... }
}Expand description
A marker trait for types that can be used as components in the ECS.
This trait must be implemented for any struct you wish to attach to an entity.
The 'static lifetime ensures that the component type does not contain any
non-static references, and Send + Sync are required to allow the component
data to be safely accessed from multiple threads.
Clone is required to allow component data to be moved between pages
during structural changes (like adding or removing components).
§Physical layout (AGDF)
The three storage hooks below let a component declare how its column is
physically laid out — the data-layer twin of GORNA’s “adapt the HOW, not the
WHAT”. They all default to the canonical Array-of-Structures column
(Vec<Self>), so existing components are bit-identical to before. A component
that opts into a field-split Structure-of-Arrays layout (via
#[component(layout = "soa")]) overrides all three to route through its
generated SoA column instead. CRPECS storage stays a Box<dyn AnyVec> either
way — only the concrete column type behind it changes.
Provided Methods§
Sourcefn make_column() -> Box<dyn AnyVec>where
Self: Sized,
fn make_column() -> Box<dyn AnyVec>where
Self: Sized,
Creates this component’s empty storage column. Default: an AoS Vec<Self>.
Sourcefn push_into_column(self, column: &mut dyn AnyVec)where
Self: Sized,
fn push_into_column(self, column: &mut dyn AnyVec)where
Self: Sized,
Appends self as a new row into its column.
§Panics
Panics if column is not this component’s column type — an internal
invariant the registry/bundle paths uphold (columns are keyed by TypeId).
Sourcefn copy_row_between(src: &dyn AnyVec, src_row: usize, dst: &mut dyn AnyVec)where
Self: Sized,
fn copy_row_between(src: &dyn AnyVec, src_row: usize, dst: &mut dyn AnyVec)where
Self: Sized,
Clones row src_row from src into dst (used when an entity migrates
between pages on a structural change). Both columns are this component’s
column type.
§Panics
Panics on a column type mismatch (same invariant as push_into_column).
Sourcefn clone_from_column(column: &dyn AnyVec, row: usize) -> Selfwhere
Self: Sized,
fn clone_from_column(column: &dyn AnyVec, row: usize) -> Selfwhere
Self: Sized,
Reads row row of column as an owned value — the uniform by-value
access path that works for both AoS (clone the &T) and field-SoA
(gather the fields) layouts. Used by World::clone_component, the
Soa<T> query, and the serialization recipe.
§Panics
Panics on a column type mismatch.
Sourcefn set_in_column(self, column: &mut dyn AnyVec, row: usize)where
Self: Sized,
fn set_in_column(self, column: &mut dyn AnyVec, row: usize)where
Self: Sized,
Overwrites row row of column with self — the uniform by-value write
path for both layouts (AoS assigns the slot; field-SoA scatters into the
lanes). Used by World::set_component.
§Panics
Panics on a column type mismatch.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl Component for MaterialRef
impl Component for MeshRef
impl Component for UiBorder
impl Component for UiColor
impl Component for UiImage
impl Component for UiInteraction
impl Component for UiNode
impl Component for UiStyle
impl Component for UiText
impl Component for UiTransform
impl Component for ActiveEvents
impl Component for AudioListener
impl Component for AudioSource
impl Component for Camera
impl Component for Children
impl Component for Collider
impl Component for CollisionEvents
impl Component for GlobalTransform
impl Component for KinematicCharacterController
impl Component for Light
impl Component for Name
impl Component for Parent
impl Component for PhysicsDebugData
impl Component for PhysicsMaterial
impl Component for Prefab
impl Component for RigidBody
impl Component for Tag
impl Component for Transform
impl<T: Asset> Component for HandleComponent<T>
Implement the Component trait to make HandleComponent usable by the ECS.