Skip to content

Commit 36a2f7f

Browse files
authored
Remove unnecessary bounds on EntityClonerBuilder::without_required_components (#17969)
## Objective The closure argument for `EntityClonerBuilder::without_required_components` has `Send + Sync + 'static` bounds, but the closure immediately gets called and never needs to be sent anywhere. (This was my fault :P ) ## Solution Remove the bounds so that users aren't unnecessarily restricted. I also took the opportunity to expand the tests a little.
1 parent 2f633c1 commit 36a2f7f

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

crates/bevy_ecs/src/entity/clone_entities.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ impl<'w> EntityClonerBuilder<'w> {
609609
/// will not involve required components.
610610
pub fn without_required_components(
611611
&mut self,
612-
builder: impl FnOnce(&mut EntityClonerBuilder) + Send + Sync + 'static,
612+
builder: impl FnOnce(&mut EntityClonerBuilder),
613613
) -> &mut Self {
614614
self.attach_required_components = false;
615615
builder(self);
@@ -1187,14 +1187,42 @@ mod tests {
11871187
let e = world.spawn(A).id();
11881188
let e_clone = world.spawn_empty().id();
11891189

1190+
EntityCloner::build(&mut world)
1191+
.deny_all()
1192+
.allow::<B>()
1193+
.clone_entity(e, e_clone);
1194+
1195+
assert_eq!(world.entity(e_clone).get::<A>(), None);
1196+
assert_eq!(world.entity(e_clone).get::<B>(), Some(&B));
1197+
assert_eq!(world.entity(e_clone).get::<C>(), Some(&C(5)));
1198+
}
1199+
1200+
#[test]
1201+
fn clone_entity_with_default_required_components() {
1202+
#[derive(Component, Clone, PartialEq, Debug)]
1203+
#[require(B)]
1204+
struct A;
1205+
1206+
#[derive(Component, Clone, PartialEq, Debug, Default)]
1207+
#[require(C(|| C(5)))]
1208+
struct B;
1209+
1210+
#[derive(Component, Clone, PartialEq, Debug)]
1211+
struct C(u32);
1212+
1213+
let mut world = World::default();
1214+
1215+
let e = world.spawn((A, C(0))).id();
1216+
let e_clone = world.spawn_empty().id();
1217+
11901218
EntityCloner::build(&mut world)
11911219
.deny_all()
11921220
.without_required_components(|builder| {
1193-
builder.allow::<B>();
1221+
builder.allow::<A>();
11941222
})
11951223
.clone_entity(e, e_clone);
11961224

1197-
assert_eq!(world.entity(e_clone).get::<A>(), None);
1225+
assert_eq!(world.entity(e_clone).get::<A>(), Some(&A));
11981226
assert_eq!(world.entity(e_clone).get::<B>(), Some(&B));
11991227
assert_eq!(world.entity(e_clone).get::<C>(), Some(&C(5)));
12001228
}

0 commit comments

Comments
 (0)