[−][src]Struct specs::world::EntityBuilder
The entity builder, allowing to build an entity together with its components.
Examples
use specs::{prelude::*, 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`
Distinguishing Mandatory Components from Optional Components
use specs::{prelude::*, storage::HashMapStorage}; struct MandatoryHealth(f32); impl Component for MandatoryHealth { type Storage = HashMapStorage<Self>; } struct OptionalPos { x: f32, y: f32, } impl Component for OptionalPos { type Storage = DenseVecStorage<Self>; } let mut world = World::new(); world.register::<MandatoryHealth>(); world.register::<OptionalPos>(); let mut entitybuilder = world.create_entity().with(MandatoryHealth(4.0)); // something trivial to serve as our conditional let include_optional = true; if include_optional == true { entitybuilder = entitybuilder.with(OptionalPos { x: 1.0, y: 3.0 }) } let entity = entitybuilder.build();
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
impl<'a> Builder for EntityBuilder<'a>
[src]
fn with<T: Component>(self, c: T) -> Self
[src]
Inserts a component for this entity.
If a component was already associated with the entity, it will overwrite the previous component.
fn build(self) -> Entity
[src]
Finishes the building and returns the entity. As opposed to
LazyBuilder
, the components are available immediately.
impl<'a> Drop for EntityBuilder<'a>
[src]
Auto Trait Implementations
impl<'a> Unpin for EntityBuilder<'a>
impl<'a> Sync for EntityBuilder<'a>
impl<'a> Send for EntityBuilder<'a>
impl<'a> !UnwindSafe for EntityBuilder<'a>
impl<'a> !RefUnwindSafe for EntityBuilder<'a>
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Resource for T where
T: Any + Send + Sync,
[src]
T: Any + Send + Sync,
impl<T> Any for T where
T: Any,
[src]
T: Any,
fn get_type_id(&self) -> TypeId
[src]
impl<T> Event for T where
T: Send + Sync + 'static,
[src]
T: Send + Sync + 'static,