pub trait Component:
Send
+ Sync
+ 'static { }Expand description
Marker trait for types that can be used as ECS components.
Components must be:
Send: Can be transferred between threadsSync: Can be shared between threads via references'static: No borrowed data (required for type erasure and storage)
§Thread Safety
The Send + Sync bounds enable parallel system execution. Systems can
safely access components from multiple threads when access patterns
don’t conflict (multiple readers or single writer).
§Implementation
Components require explicit opt-in via implementation:
use goud_engine::ecs::Component;
struct Health(pub f32);
impl Component for Health {}This is intentional - not all Send + Sync + 'static types should
automatically be components. The explicit implementation:
- Documents intent that this type is meant for ECS use
- Allows future derive macro to add behavior
- Prevents accidental use of inappropriate types as components
§What Makes a Good Component?
- Data-only: Components should be pure data, no behavior
- Small: Prefer many small components over few large ones
- Focused: Each component represents one aspect of an entity
Good:
struct Position { x: f32, y: f32, z: f32 }
impl Component for Position {}
struct Velocity { x: f32, y: f32, z: f32 }
impl Component for Velocity {}Avoid:
ⓘ
// Too large - combines unrelated data
struct Entity {
position: (f32, f32, f32),
velocity: (f32, f32, f32),
health: f32,
name: String,
}Implementors§
impl Component for AnimationController
impl Component for SkeletalAnimator
impl Component for SkeletalMesh2D
impl Component for Skeleton2D
impl Component for SpriteAnimator
impl Component for PrefabRef
impl Component for AudioSource
impl Component for Children
impl Component for Collider
impl Component for GlobalTransform2D
impl Component for GlobalTransform
impl Component for Name
impl Component for Parent
impl Component for RigidBody
ECS component trait implementation.