pub trait Component: Send + Sync + 'static {
    const IS_IMMUTABLE: bool = false;
}
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 systems, use the Fetcher system parameter.

§Deriving

The Component trait can be implemented automatically by using the associated derive macro. However, the type must still satisfy the Send + Sync + '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);

Provided Associated Constants§

source

const IS_IMMUTABLE: bool = false

Whether or not this component is immutable.

Immutable components disallow mutable references, which can be used to ensure components are used in particular ways.

Object Safety§

This trait is not object safe.

Implementors§