Struct specs::world::EntityBuilder

source ·
pub struct EntityBuilder<'a> {
    pub entity: Entity,
    pub world: &'a World,
    /* private fields */
}
Expand description

The entity builder, allowing to build an entity together with its components.

Examples

use specs::prelude::*;
use specs::storage::HashMapStorage;

struct Health(f32);

impl Component for Health {
    type Storage = HashMapStorage<Self>;
}

struct Pos {
    x: f32,
    y: f32,
}

impl Component for Pos {
    type Storage = DenseVecStorage<Self>;
}

let mut world = World::new();
world.register::<Health>();
world.register::<Pos>();

let entity = world
    .create_entity() // This call returns `EntityBuilder`
    .with(Health(4.0))
    .with(Pos { x: 1.0, y: 3.0 })
    .build(); // Returns the `Entity`

Fields

entity: Entity

The (already created) entity for which components will be inserted.

world: &'a World

A reference to the World for component insertions.

Trait Implementations

Inserts a component for this entity.

If a component was already associated with the entity, it will overwrite the previous component.

Finishes the building and returns the entity. As opposed to LazyBuilder, the components are available immediately.

Executes the destructor for this type. Read more
Add a Marker to the entity by fetching the associated allocator. 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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.