pub trait Bundle {
// Required method
fn into_bundle(self) -> DynamicBundle;
// Provided method
fn name(&self) -> &'static str { ... }
}Expand description
A set of components to spawn an entity with.
Implemented for a DynamicBundle, which is what the crate::bundle! macro
produces, and for any type of a caller’s own that can say what its
components are. It is deliberately not implemented for tuples: every
'static type is a component, so a tuple impl would make (a, b) mean two
components in one place and one component in another.
A caller’s own type is the usual way to spawn an object: give it the fields
it is built from, and build its components in Bundle::into_bundle.
struct Cube {
size: f32,
}
impl Bundle for Cube {
fn into_bundle(self) -> DynamicBundle {
bundle![self.size]
}
}
let mut world = World::new();
let cube = world.root_scope_mut().spawn(Cube { size: 1.0 });
assert!(cube.name().ends_with("::Cube"), "the entity is named after the object");Required Methods§
Sourcefn into_bundle(self) -> DynamicBundle
fn into_bundle(self) -> DynamicBundle
The dynamic bundle holding exactly this bundle’s components.
The bundle supplies the whole bundle, so there is no target to append to
or overwrite. A caller gathering several bundles into one spawn pushes
each onto a DynamicBundle with DynamicBundle::push_bundle.
Provided Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
The name the spawned entity takes: the bundle’s own type by default.
A DynamicBundle has a name of its own — the source position of the
crate::bundle! that wrote it, or the label DynamicBundle::named
gave it — and answers with that. A type of the caller’s own has no such
label to speak of, so it names the entity after itself, which is the
object the entity is. A bundle that names itself after something else
overrides this.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".