Trait SpawnRelated

Source
pub trait SpawnRelated: RelationshipTarget {
    // Required methods
    fn spawn<L: SpawnableList<Self::Relationship>>(
        list: L,
    ) -> SpawnRelatedBundle<Self::Relationship, L>;
    fn spawn_one<B: Bundle>(bundle: B) -> SpawnOneRelated<Self::Relationship, B>;
}
Expand description

RelationshipTarget methods that create a Bundle with a DynamicBundle::Effect that:

  1. Contains the RelationshipTarget component, pre-allocated with the necessary space for spawned entities.
  2. Spawns an entity (or a list of entities) that relate to the entity the Bundle is added to via the RelationshipTarget::Relationship.

Required Methods§

Source

fn spawn<L: SpawnableList<Self::Relationship>>( list: L, ) -> SpawnRelatedBundle<Self::Relationship, L>

Returns a Bundle containing this RelationshipTarget component. It also spawns a SpawnableList of entities, each related to the bundle’s entity via RelationshipTarget::Relationship. The RelationshipTarget (when possible) will pre-allocate space for the related entities.

See Spawn, SpawnIter, and SpawnWith for usage examples.

Source

fn spawn_one<B: Bundle>(bundle: B) -> SpawnOneRelated<Self::Relationship, B>

Returns a Bundle containing this RelationshipTarget component. It also spawns a single entity containing Bundle that is related to the bundle’s entity via RelationshipTarget::Relationship.

let mut world = World::new();
world.spawn((
    Name::new("Root"),
    Children::spawn_one(Name::new("Child")),
));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§