logo
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 Components.

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

Required Methods

Gets this Bundle’s component ids, in the order of this bundle’s Components

Calls func, which should return data for each component in the bundle, in the order of this bundle’s Components

Safety

Caller must return data for each component in the bundle, in the order of this bundle’s Components

Calls func on each value, in the order of this bundle’s Components. This will std::mem::forget the bundle fields, so callers are responsible for dropping the fields if that is desirable.

Implementations on Foreign Types

Implementors

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order

SAFE: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order