Struct EntityBuilder

Source
pub struct EntityBuilder { /* private fields */ }
Expand description

Build entities when exact set of components is not known at compile time.

Components can be added to EntityBuilder at runtime using EntityBuilder::add or EntityBuilder::with. EntityBuilder then can be used to insert components into entity or spawn a new entity.

Implementations§

Source§

impl EntityBuilder

Source

pub fn new() -> Self

Creates new empty entity builder.

Source

pub fn with<T>(self, value: T) -> Self
where T: Component + Send,

Adds component to the builder. If builder already had this component, old value is replaced.

Source

pub fn add<T>(&mut self, value: T) -> &mut Self
where T: Component + Send,

Adds component to the builder. If builder already had this component, old value is replaced.

Source

pub fn get<T>(&self) -> Option<&T>
where T: 'static,

Returns reference to component from builder.

Source

pub fn get_mut<T>(&mut self) -> Option<&mut T>
where T: 'static,

Returns mutable reference to component from builder.

Source

pub fn component_types(&self) -> impl Iterator<Item = &ComponentInfo>

Returns iterator over component types in this builder.

Source

pub fn is_empty(&self) -> bool

Returns true of the builder is empty.

Trait Implementations§

Source§

impl Debug for EntityBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for EntityBuilder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl DynamicBundle for EntityBuilder

Source§

fn valid(&self) -> bool

Returns true if given bundle is valid.
Source§

fn contains_id(&self, ty: TypeId) -> bool

Returns true if bundle has specified type id.
Source§

fn with_ids<R>(&self, f: impl FnOnce(&[TypeId]) -> R) -> R

Calls provided closure with slice of ids of types that this bundle contains.
Source§

fn put(self, f: impl FnMut(NonNull<u8>, TypeId, usize))

Calls provided closure with pointer to a component, its type and size. Closure is expected to read components from the pointer and take ownership.
Source§

fn key() -> Option<TypeId>

Returns static key if the bundle type have one.
Source§

impl DynamicComponentBundle for EntityBuilder

Source§

fn with_components<R>(&self, f: impl FnOnce(&[ComponentInfo]) -> R) -> R

Calls provided closure with slice of component infos of types that this bundle contains.
Source§

impl Send for EntityBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.