pub unsafe trait Bundle: 'static + Send + Sync {
fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
;
unsafe fn from_components(func: impl FnMut() -> *mut u8) -> Self;
fn get_components(self, func: impl FnMut(*mut u8));
}
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, Global>ⓘ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, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
unsafe fn from_components(func: impl FnMut() -> *mut u8) -> Self
unsafe fn from_components(func: impl FnMut() -> *mut u8) -> Self
fn get_components(self, func: impl FnMut(*mut u8))
fn get_components(self, func: impl FnMut(*mut u8))
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
impl<C0> Bundle for (C0,) where
C0: Component,
impl<C0> Bundle for (C0,) where
C0: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(func: impl FnMut() -> *mut u8) -> (C0,)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5> Bundle for (C0, C1, C2, C3, C4, C5) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
impl<C0, C1, C2, C3, C4, C5> Bundle for (C0, C1, C2, C3, C4, C5) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
C8: Component,
C9: Component,
C10: Component,
C11: Component,
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
C8: Component,
C9: Component,
C10: Component,
C11: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6> Bundle for (C0, C1, C2, C3, C4, C5, C6) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
impl<C0, C1, C2, C3, C4, C5, C6> Bundle for (C0, C1, C2, C3, C4, C5, C6) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6, C7> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
impl<C0, C1, C2, C3, C4, C5, C6, C7> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6, C7)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12) where
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,
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12) where
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,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2> Bundle for (C0, C1, C2) where
C0: Component,
C1: Component,
C2: Component,
impl<C0, C1, C2> Bundle for (C0, C1, C2) where
C0: Component,
C1: Component,
C2: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(func: impl FnMut() -> *mut u8) -> (C0, C1, C2)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13) where
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,
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13) where
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,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
C8: Component,
C9: Component,
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
C8: Component,
C9: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3> Bundle for (C0, C1, C2, C3) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
impl<C0, C1, C2, C3> Bundle for (C0, C1, C2, C3) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(func: impl FnMut() -> *mut u8) -> (C0, C1, C2, C3)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14) where
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,
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14) where
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,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl Bundle for ()
impl Bundle for ()
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(func: impl FnMut() -> *mut u8)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1> Bundle for (C0, C1) where
C0: Component,
C1: Component,
impl<C0, C1> Bundle for (C0, C1) where
C0: Component,
C1: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(func: impl FnMut() -> *mut u8) -> (C0, C1)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
C8: Component,
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
C8: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6, C7, C8)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
C8: Component,
C9: Component,
C10: Component,
impl<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10> Bundle for (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
C5: Component,
C6: Component,
C7: Component,
C8: Component,
C9: Component,
C10: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10)
pub fn get_components(self, func: impl FnMut(*mut u8))
impl<C0, C1, C2, C3, C4> Bundle for (C0, C1, C2, C3, C4) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
impl<C0, C1, C2, C3, C4> Bundle for (C0, C1, C2, C3, C4) where
C0: Component,
C1: Component,
C2: Component,
C3: Component,
C4: Component,
pub fn component_ids(
components: &mut Components,
storages: &mut Storages
) -> Vec<ComponentId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub unsafe fn from_components(
func: impl FnMut() -> *mut u8
) -> (C0, C1, C2, C3, C4)
pub fn get_components(self, func: impl FnMut(*mut u8))
Implementors
impl Bundle for DirectionalLightBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for PointLightBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for OrthographicCameraBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for PerspectiveCameraBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for SpriteBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for SpriteSheetBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for Text2dBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for ButtonBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for ImageBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for NodeBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for TextBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl Bundle for UiCameraBundle
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl<M> Bundle for MaterialMeshBundle<M> where
M: SpecializedMaterial,
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
impl<M> Bundle for MaterialMesh2dBundle<M> where
M: SpecializedMaterial2d,
SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order