Struct hecs::EntityBuilder[][src]

pub struct EntityBuilder { /* fields omitted */ }

Helper for incrementally constructing a bundle of components with dynamic component types

Prefer reusing the same builder over creating new ones repeatedly.

let mut world = World::new();
let mut builder = EntityBuilder::new();
builder.add(123).add("abc");
let e = world.spawn(builder.build()); // builder can now be reused
assert_eq!(*world.get::<i32>(e).unwrap(), 123);
assert_eq!(*world.get::<&str>(e).unwrap(), "abc");

Implementations

impl EntityBuilder[src]

pub fn new() -> Self[src]

Create a builder representing an entity with no components

pub fn add<T: Component>(&mut self, component: T) -> &mut Self[src]

Add component to the entity.

If the bundle already contains a component of type T, it will be dropped and replaced with the most recently added one.

pub fn add_bundle(&mut self, bundle: impl DynamicBundle) -> &mut Self[src]

Add all components in bundle to the entity.

If the bundle contains any component which matches the type of a component already in the EntityBuilder, the newly added component from the bundle will replace the old component and the old component will be dropped.

pub fn has<T: Component>(&self) -> bool[src]

Checks to see if the component of type T exists

pub fn get<T: Component>(&self) -> Option<&T>[src]

Borrow the component of type T, if it exists

pub fn get_mut<T: Component>(&mut self) -> Option<&mut T>[src]

Uniquely borrow the component of type T, if it exists

pub fn component_types(&self) -> impl Iterator<Item = TypeId> + '_[src]

Enumerate the types of the entity builder’s components

pub fn build(&mut self) -> BuiltEntity<'_>[src]

Construct a Bundle suitable for spawning

pub fn clear(&mut self)[src]

Drop previously added components

The builder is cleared implicitly when an entity is built, so this doesn’t usually need to be called.

Trait Implementations

impl Default for EntityBuilder[src]

fn default() -> Self[src]

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

impl Drop for EntityBuilder[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl Send for EntityBuilder[src]

impl Sync for EntityBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.