Entity

Trait Entity 

Source
pub trait Entity: Any + Default {
    // Required methods
    fn id() -> usize;
    fn as_any(&self) -> &dyn Any;
    fn as_any_mut(&mut self) -> &mut dyn Any;

    // Provided methods
    fn name() -> &'static str { ... }
    fn type_id() -> TypeId { ... }
    fn property_ids() -> &'static [TypeId] { ... }
    fn required_property_ids() -> &'static [TypeId] { ... }
    fn new_boxed() -> Box<Self> { ... }
}
Expand description

All entities must implement this trait using the define_entity! macro.

Required Methods§

Source

fn id() -> usize

The index of this item in the owner, which is initialized globally per type upon first access. We explicitly initialize this in a ctor in order to know how many Entity types exist globally when we construct any EntityStore.

Source

fn as_any(&self) -> &dyn Any

Standard pattern for downcasting to concrete types.

Source

fn as_any_mut(&mut self) -> &mut dyn Any

Provided Methods§

Source

fn name() -> &'static str

Source

fn type_id() -> TypeId

Source

fn property_ids() -> &'static [TypeId]

Get a list of all properties this Entity has. This list is static, computed in with ctor magic.

Source

fn required_property_ids() -> &'static [TypeId]

Get a list of all properties of this Entity that must be supplied when a new entity is created.

Source

fn new_boxed() -> Box<Self>

Creates a new boxed instance of the item.

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§