pub unsafe trait Bundle: Send + Sync + 'static {
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
;
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self
where
F: FnMut(&mut T) -> OwningPtr<'_>,
Self: Sized;
fn get_components(self, func: impl FnMut(OwningPtr<'_>));
}
Expand description
An ordered collection of Component
s.
Commonly used for spawning entities and adding and removing components in bulk. This
trait is automatically implemented for tuples of components: (ComponentA, ComponentB)
is a very convenient shorthand when working with one-off collections of components. Note
that both the unit type ()
and (ComponentA, )
are valid bundles. The unit bundle is
particularly useful for spawning multiple empty entities by using
Commands::spawn_batch
.
Examples
Typically, you will simply use #[derive(Bundle)]
when creating your own Bundle
. Each
struct field is a component:
#[derive(Bundle)]
struct MyBundle {
a: ComponentA,
b: ComponentB,
c: ComponentC,
}
You can nest bundles using the #[bundle]
attribute:
#[derive(Component)]
struct X(i32);
#[derive(Component)]
struct Y(u64);
#[derive(Component)]
struct Z(String);
#[derive(Bundle)]
struct A {
x: X,
y: Y,
}
#[derive(Bundle)]
struct B {
#[bundle]
a: A,
z: Z,
}
Safety
Bundle::component_ids
must return theComponentId
for each component type in the bundle, in the exact order thatBundle::get_components
is called.Bundle::from_components
must callfunc
exactly once for eachComponentId
returned byBundle::component_ids
.
Required Methods
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
Calls func
on each value, in the order of this bundle’s Component
s. This will
std::mem::forget
the bundle fields, so callers are responsible for dropping the fields
if that is desirable.
Implementations on Foreign Types
sourceimpl Bundle for ()
impl Bundle for ()
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component> Bundle for (C0,)
impl<C0: Component> Bundle for (C0,)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component> Bundle for (C0, C1)
impl<C0: Component, C1: Component> Bundle for (C0, C1)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component> Bundle for (C0, C1, C2)
impl<C0: Component, C1: Component, C2: Component> Bundle for (C0, C1, C2)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component> Bundle for (C0, C1, C2, C3)
impl<C0: Component, C1: Component, C2: Component, C3: Component> Bundle for (C0, C1, C2, C3)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component> Bundle for (C0, C1, C2, C3, C4)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component> Bundle for (C0, C1, C2, C3, C4)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component> Bundle for (C0, C1, C2, C3, C4, C5)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component> Bundle for (C0, C1, C2, C3, C4, C5)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component, C11: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component, C11: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component, C11: Component, C12: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component, C11: Component, C12: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component, C11: Component, C12: Component, C13: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component, C11: Component, C12: Component, C13: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components<T, F>(ctx: &mut T, func: F) -> Self where
F: FnMut(&mut T) -> OwningPtr<'_>,
fn get_components(self, func: impl FnMut(OwningPtr<'_>))
sourceimpl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component, C11: Component, C12: Component, C13: Component, C14: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14)
impl<C0: Component, C1: Component, C2: Component, C3: Component, C4: Component, C5: Component, C6: Component, C7: Component, C8: Component, C9: Component, C10: Component, C11: Component, C12: Component, C13: Component, C14: Component> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14)
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,