Trait rfw::ecs::Bundle[][src]

pub unsafe trait Bundle: 'static + Send + Sync {
    fn type_info() -> Vec<TypeInfo, Global>;
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.

You cannot query for a bundle, only individual components within it.

Typically, you will simply use #[derive(Bundle)] when creating your own Bundle. The Bundle 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 () and (ComponentA, ) are valid tuples.

You can nest bundles like so:


#[derive(Bundle)]
struct A {
    x: i32,
    y: u64,
}

#[derive(Bundle)]
struct B {
    #[bundle]
    a: A,
    z: String,
  }

Safety

Bundle::type_info must return the TypeInfo for each component type in the bundle, in the exact order that Bundle::get_components is called. Bundle::from_components must call func exactly once for each TypeInfo returned by Bundle::type_info

Required methods

Gets this Bundle’s components type info, 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 “mem::forget” the bundle fields, so callers are responsible for dropping the fields if that is desirable.

Implementations on Foreign Types

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

SAFE: TypeInfo is returned in tuple-order. Bundle::from_components and Bundle::get_components use tuple-order

Implementors