Skip to content

Commit 6d72258

Browse files
authored
Remove default implementation of extend_from_iter from RelationshipSourceCollection (#20255)
# Objective - Remove the default implementation of `extend_from_iter` from the RelationshipSourceCollection trait to standardize collection types providing their own implementation. - Fixes #20253 ## Solution - Removed the default implementation of `extend_from_iter` - Added `extend_from_iter` implementation for BTreeSet that uses its native .extend() method - All other collection types (Vec, SmallVec, EntityHashSet, IndexSet, EntityIndexSet, Entity) already had their own implementations
1 parent 18152a7 commit 6d72258

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

crates/bevy_ecs/src/relationship/relationship_source_collection.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,7 @@ pub trait RelationshipSourceCollection {
7878
/// Add multiple entities to collection at once.
7979
///
8080
/// May be faster than repeatedly calling [`Self::add`].
81-
fn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>) {
82-
// The method name shouldn't conflict with `Extend::extend` as it's in the rust prelude and
83-
// would always conflict with it.
84-
for entity in entities {
85-
self.add(entity);
86-
}
87-
}
81+
fn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>);
8882
}
8983

9084
/// This trait signals that a [`RelationshipSourceCollection`] is ordered.
@@ -582,6 +576,10 @@ impl RelationshipSourceCollection for BTreeSet<Entity> {
582576
fn shrink_to_fit(&mut self) {
583577
// BTreeSet doesn't have a capacity
584578
}
579+
580+
fn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>) {
581+
self.extend(entities);
582+
}
585583
}
586584

587585
#[cfg(test)]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Remove default implementation of extend_from_iter from RelationshipSourceCollection
3+
pull_requests: [20255]
4+
---
5+
6+
The `extend_from_iter` method in the `RelationshipSourceCollection` trait no longer has a default implementation. If you have implemented a custom relationship source collection, you must now provide your own implementation of this method.
7+
8+
```rust
9+
// Before: method was optional due to default implementation
10+
impl RelationshipSourceCollection for MyCustomCollection {
11+
// ... other required methods
12+
// extend_from_iter was automatically provided
13+
}
14+
15+
// After: method is now required
16+
impl RelationshipSourceCollection for MyCustomCollection {
17+
// ... other required methods
18+
fn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>) {
19+
// Use your collection's native extend method if available
20+
self.extend(entities);
21+
// Or implement manually if needed:
22+
// for entity in entities {
23+
// self.add(entity);
24+
// }
25+
}
26+
}
27+
```

0 commit comments

Comments
 (0)