Skip to main content

DynamicBundle

Struct DynamicBundle 

Source
pub struct DynamicBundle {
    components: Vec<BundleComponent>,
    name: &'static str,
}
Expand description

A bundle assembled at runtime.

This is what crate::bundle! writes and what a Bundle implementation builds its components into. A type of the caller’s own is the usual way to spawn an object; reach for this one when the components are only known once the program runs.

It also carries the name of the entity it will spawn, which by default is the source position of the crate::bundle! that built it.

Fields§

§components: Vec<BundleComponent>§name: &'static str

Implementations§

Source§

impl DynamicBundle

Source

pub fn new() -> Self

An empty bundle with no name, for one built by hand.

crate::bundle! is what supplies a name, so a bundle filled in by hand names its entity after nothing: give it one with DynamicBundle::named, or spawn it with ScopeMut::spawn_named.

Source

pub fn named(self, name: &'static str) -> Self

Name the bundle, replacing the one crate::bundle! gave it.

crate::bundle! names every bundle it builds after the source position that wrote it, and a spawn gives that name to the entity. A bundle assembled at runtime has no such position to speak of, so it names itself here instead.

Source

pub fn push_component<C: 'static>(&mut self, value: C)

Add one component.

The value is stored under its own type, so a tuple pushed here stays one component.

Source

pub fn push_bundle<B: Bundle>(&mut self, bundle: B)

Add every component of bundle to this one.

This is how a caller gathers several bundles into one spawn: the components keep their own types, so a bundle that holds a tuple contributes that tuple as a single component, exactly as spawning it alone would.

Source

pub(crate) fn finish(self) -> Vec<BundleComponent>

The components in type order.

§Panics

When the same component appears twice. The duplicate is caught here rather than at spawn so that every path into an archetype, queued or immediate, reports it from the call that wrote the bundle.

Trait Implementations§

Source§

impl Bundle for DynamicBundle

Source§

fn name(&self) -> &'static str

The name the spawned entity takes: the bundle’s own type by default. Read more
Source§

fn into_bundle(self) -> DynamicBundle

The dynamic bundle holding exactly this bundle’s components. Read more
Source§

impl Default for DynamicBundle

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Component for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more