Struct shipyard::Entities[][src]

pub struct Entities { /* fields omitted */ }
Expand description

Entities holds the EntityIds to all entities: living, removed and dead.

A living entity is an entity currently present, with or without component.

Removed and dead entities don’t have any component.

The big difference is that removed ones can become alive again.

The life cycle of an entity looks like this:

Generation -> Deletion -> Dead
          ⬑–––––↵

Implementations

Returns true if entity matches a living entity.

Adds component to entity, multiple components can be added at the same time using a tuple.
Entities is only borrowed immutably.

Example

let world = World::new();
let entity = world.run::<EntitiesMut, _, _>(|mut entities| {
    entities.add_entity((), ())
});
let (entities, mut u32s) = world.borrow::<(Entities, &mut u32)>();
entities.try_add_component(&mut u32s, 0, entity).unwrap();

Adds component to entity, multiple components can be added at the same time using a tuple.
Entities is only borrowed immutably.
Unwraps errors.

Example

let world = World::new();
let entity = world.run::<EntitiesMut, _, _>(|mut entities| {
    entities.add_entity((), ())
});
let (entities, mut u32s) = world.borrow::<(Entities, &mut u32)>();
entities.add_component(&mut u32s, 0, entity);

Delete an entity, returns true if the entity was alive.
If the entity has components, they will not be deleted and still be accessible using this id.

Stores component in a new entity, the EntityId to this entity is returned.
Multiple components can be added at the same time using a tuple.

Example:

let world = World::new();

world.run::<(EntitiesMut, &mut usize, &mut u32), _, _>(|(mut entities, mut usizes, mut u32s)| {
    let entity = entities.add_entity((&mut usizes, &mut u32s), (0, 1));

    assert_eq!(usizes.get(entity), Ok(&0));
    assert_eq!(u32s.get(entity), Ok(&1));
});

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.