pub trait Component: 'static {
type Mutability: MutabilityMarker;
}
Expand description
Types which store data on entities.
A Component
is a piece of data which can be attached to an entity. An
entity can have any combination of components, but cannot have more than one
component of the same type.
To add a component to an entity, use the Insert
event. To access
components from handlers, use the Fetcher
handler parameter.
§Deriving
The Component
trait can be implemented automatically by using the
associated derive macro. However, the type must still satisfy the 'static
bound to do so.
use evenio::prelude::*;
// Component with some data.
#[derive(Component)]
struct Username(String);
// Component without data, known as a "marker" or "tag" component.
struct Invisible;
// Derive it on structs with named fields.
#[derive(Component)]
struct Position {
x: f32,
y: f32,
z: f32,
}
// ...and on enums.
#[derive(Component)]
enum FriendStatus {
Friendly,
Neutral,
Unfriendly,
}
// Components can be immutable, which disallows mutable references
// to the component once it's attached to an entity.
#[derive(Component)]
#[component(immutable)] // Override the default mutability.
struct FooCounter(i32);