Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/bevy_ecs/src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,19 @@ impl<R: Relationship, F: FnOnce(&mut RelatedSpawner<R>) + Send + Sync + 'static>
/// Children::spawn((
/// Spawn(Name::new("Child1")),
/// // This adds the already existing entities as children of Root.
/// WithRelated([child2, child3].into_iter()),
/// WithRelated::new([child2, child3]),
/// )),
/// ));
/// ```
pub struct WithRelated<I>(pub I);

impl<I> WithRelated<I> {
/// Creates a new [`WithRelated`] from a collection of entities.
pub fn new(iter: impl IntoIterator<IntoIter = I>) -> Self {
Self(iter.into_iter())
}
}

impl<R: Relationship, I: Iterator<Item = Entity>> SpawnableList<R> for WithRelated<I> {
fn spawn(self, world: &mut World, entity: Entity) {
world
Expand Down Expand Up @@ -653,7 +660,7 @@ mod tests {
let parent = world
.spawn((
Name::new("Parent"),
Children::spawn(WithRelated([child1, child2].into_iter())),
Children::spawn(WithRelated::new([child1, child2])),
))
.id();

Expand Down
Loading