Trait zengine_ecs::Component
source · [−]Expand description
A data type that can be used to store data for an Entity
Component is a derivable trait:
you could implement it by applying a #[derive(Component)] attribute to your data type.
To correctly implement this trait your data must satisfy the Sync + Send + Debug trait bounds.
Implementing the trait for foreign types
As a consequence of the orphan rule, it is not possible to separate into two different crates the implementation of Component from the definition of a type. For this reason is not possible to implement the Component trat for a type defined in a third party library. The newtype pattern is a simple workaround to this limitation:
The following example gives a demonstration of this pattern.
use external_crate::TypeThatShouldBeAComponent;
#[derive(Component)]
struct MyWrapper(TypeThatShouldBeAComponent)