Skip to content

Commit f55a027

Browse files
committed
Rename Command's write method to apply and update impls/calls to it
1 parent 527d3a5 commit f55a027

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

crates/bevy_ecs/src/system/commands/command_queue.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl CommandQueue {
5757
// SAFETY: According to the invariants of `CommandMeta.apply_command_and_get_size`,
5858
// `command` must point to a value of type `C`.
5959
let command: C = unsafe { command.read_unaligned() };
60-
command.write(world);
60+
command.apply(world);
6161
std::mem::size_of::<C>()
6262
},
6363
};
@@ -165,7 +165,7 @@ mod test {
165165
}
166166

167167
impl Command for DropCheck {
168-
fn write(self, _: &mut World) {}
168+
fn apply(self, _: &mut World) {}
169169
}
170170

171171
#[test]
@@ -191,7 +191,7 @@ mod test {
191191
struct SpawnCommand;
192192

193193
impl Command for SpawnCommand {
194-
fn write(self, world: &mut World) {
194+
fn apply(self, world: &mut World) {
195195
world.spawn_empty();
196196
}
197197
}
@@ -219,7 +219,7 @@ mod test {
219219
// some data added to it.
220220
struct PanicCommand(String);
221221
impl Command for PanicCommand {
222-
fn write(self, _: &mut World) {
222+
fn apply(self, _: &mut World) {
223223
panic!("command is panicking");
224224
}
225225
}
@@ -267,7 +267,7 @@ mod test {
267267

268268
struct CommandWithPadding(u8, u16);
269269
impl Command for CommandWithPadding {
270-
fn write(self, _: &mut World) {}
270+
fn apply(self, _: &mut World) {}
271271
}
272272

273273
#[cfg(miri)]

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use super::{Deferred, Resource, SystemBuffer, SystemMeta};
3232
/// struct AddToCounter(u64);
3333
///
3434
/// impl Command for AddToCounter {
35-
/// fn write(self, world: &mut World) {
35+
/// fn apply(self, world: &mut World) {
3636
/// let mut counter = world.get_resource_or_insert_with(Counter::default);
3737
/// counter.0 += self.0;
3838
/// }
@@ -43,8 +43,8 @@ use super::{Deferred, Resource, SystemBuffer, SystemMeta};
4343
/// }
4444
/// ```
4545
pub trait Command: Send + 'static {
46-
/// Executes this command.
47-
fn write(self, world: &mut World);
46+
/// Applies this command.
47+
fn apply(self, world: &mut World);
4848
}
4949

5050
/// A [`Command`] queue to perform impactful changes to the [`World`].
@@ -522,7 +522,7 @@ impl<'w, 's> Commands<'w, 's> {
522522
/// struct AddToCounter(u64);
523523
///
524524
/// impl Command for AddToCounter {
525-
/// fn write(self, world: &mut World) {
525+
/// fn apply(self, world: &mut World) {
526526
/// let mut counter = world.get_resource_or_insert_with(Counter::default);
527527
/// counter.0 += self.0;
528528
/// }
@@ -569,7 +569,7 @@ impl<'w, 's> Commands<'w, 's> {
569569
/// struct CountName;
570570
///
571571
/// impl EntityCommand for CountName {
572-
/// fn write(self, id: Entity, world: &mut World) {
572+
/// fn apply(self, id: Entity, world: &mut World) {
573573
/// // Get the current value of the counter, and increment it for next time.
574574
/// let mut counter = world.resource_mut::<Counter>();
575575
/// let i = counter.0;
@@ -605,7 +605,7 @@ impl<'w, 's> Commands<'w, 's> {
605605
/// ```
606606
pub trait EntityCommand: Send + 'static {
607607
/// Executes this command for the given [`Entity`].
608-
fn write(self, id: Entity, world: &mut World);
608+
fn apply(self, id: Entity, world: &mut World);
609609
/// Returns a [`Command`] which executes this [`EntityCommand`] for the given [`Entity`].
610610
fn with_entity(self, id: Entity) -> WithEntity<Self>
611611
where
@@ -623,8 +623,8 @@ pub struct WithEntity<C: EntityCommand> {
623623

624624
impl<C: EntityCommand> Command for WithEntity<C> {
625625
#[inline]
626-
fn write(self, world: &mut World) {
627-
self.cmd.write(self.id, world);
626+
fn apply(self, world: &mut World) {
627+
self.cmd.apply(self.id, world);
628628
}
629629
}
630630

@@ -829,7 +829,7 @@ impl<F> Command for F
829829
where
830830
F: FnOnce(&mut World) + Send + 'static,
831831
{
832-
fn write(self, world: &mut World) {
832+
fn apply(self, world: &mut World) {
833833
self(world);
834834
}
835835
}
@@ -838,7 +838,7 @@ impl<F> EntityCommand for F
838838
where
839839
F: FnOnce(Entity, &mut World) + Send + 'static,
840840
{
841-
fn write(self, id: Entity, world: &mut World) {
841+
fn apply(self, id: Entity, world: &mut World) {
842842
self(id, world);
843843
}
844844
}
@@ -854,7 +854,7 @@ impl<T> Command for Spawn<T>
854854
where
855855
T: Bundle,
856856
{
857-
fn write(self, world: &mut World) {
857+
fn apply(self, world: &mut World) {
858858
world.spawn(self.bundle);
859859
}
860860
}
@@ -876,7 +876,7 @@ where
876876
I: IntoIterator + Send + Sync + 'static,
877877
I::Item: Bundle,
878878
{
879-
fn write(self, world: &mut World) {
879+
fn apply(self, world: &mut World) {
880880
world.spawn_batch(self.bundles_iter);
881881
}
882882
}
@@ -901,7 +901,7 @@ where
901901
B: Bundle,
902902
I::IntoIter: Iterator<Item = (Entity, B)>,
903903
{
904-
fn write(self, world: &mut World) {
904+
fn apply(self, world: &mut World) {
905905
if let Err(invalid_entities) = world.insert_or_spawn_batch(self.bundles_iter) {
906906
error!(
907907
"Failed to 'insert or spawn' bundle of type {} into the following invalid entities: {:?}",
@@ -921,7 +921,7 @@ pub struct Despawn {
921921
}
922922

923923
impl Command for Despawn {
924-
fn write(self, world: &mut World) {
924+
fn apply(self, world: &mut World) {
925925
world.despawn(self.entity);
926926
}
927927
}
@@ -938,7 +938,7 @@ impl<T> Command for Insert<T>
938938
where
939939
T: Bundle + 'static,
940940
{
941-
fn write(self, world: &mut World) {
941+
fn apply(self, world: &mut World) {
942942
if let Some(mut entity) = world.get_entity_mut(self.entity) {
943943
entity.insert(self.bundle);
944944
} else {
@@ -961,7 +961,7 @@ impl<T> Command for Remove<T>
961961
where
962962
T: Bundle,
963963
{
964-
fn write(self, world: &mut World) {
964+
fn apply(self, world: &mut World) {
965965
if let Some(mut entity_mut) = world.get_entity_mut(self.entity) {
966966
entity_mut.remove::<T>();
967967
}
@@ -985,7 +985,7 @@ pub struct InitResource<R: Resource + FromWorld> {
985985
}
986986

987987
impl<R: Resource + FromWorld> Command for InitResource<R> {
988-
fn write(self, world: &mut World) {
988+
fn apply(self, world: &mut World) {
989989
world.init_resource::<R>();
990990
}
991991
}
@@ -1006,7 +1006,7 @@ pub struct InsertResource<R: Resource> {
10061006
}
10071007

10081008
impl<R: Resource> Command for InsertResource<R> {
1009-
fn write(self, world: &mut World) {
1009+
fn apply(self, world: &mut World) {
10101010
world.insert_resource(self.resource);
10111011
}
10121012
}
@@ -1017,7 +1017,7 @@ pub struct RemoveResource<R: Resource> {
10171017
}
10181018

10191019
impl<R: Resource> Command for RemoveResource<R> {
1020-
fn write(self, world: &mut World) {
1020+
fn apply(self, world: &mut World) {
10211021
world.remove_resource::<R>();
10221022
}
10231023
}
@@ -1037,7 +1037,7 @@ pub struct LogComponents {
10371037
}
10381038

10391039
impl Command for LogComponents {
1040-
fn write(self, world: &mut World) {
1040+
fn apply(self, world: &mut World) {
10411041
let debug_infos: Vec<_> = world
10421042
.inspect_entity(self.entity)
10431043
.into_iter()

crates/bevy_hierarchy/src/child_builder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub struct AddChild {
169169
}
170170

171171
impl Command for AddChild {
172-
fn write(self, world: &mut World) {
172+
fn apply(self, world: &mut World) {
173173
world.entity_mut(self.parent).add_child(self.child);
174174
}
175175
}
@@ -183,7 +183,7 @@ pub struct InsertChildren {
183183
}
184184

185185
impl Command for InsertChildren {
186-
fn write(self, world: &mut World) {
186+
fn apply(self, world: &mut World) {
187187
world
188188
.entity_mut(self.parent)
189189
.insert_children(self.index, &self.children);
@@ -198,7 +198,7 @@ pub struct PushChildren {
198198
}
199199

200200
impl Command for PushChildren {
201-
fn write(self, world: &mut World) {
201+
fn apply(self, world: &mut World) {
202202
world.entity_mut(self.parent).push_children(&self.children);
203203
}
204204
}
@@ -210,7 +210,7 @@ pub struct RemoveChildren {
210210
}
211211

212212
impl Command for RemoveChildren {
213-
fn write(self, world: &mut World) {
213+
fn apply(self, world: &mut World) {
214214
remove_children(self.parent, &self.children, world);
215215
}
216216
}
@@ -222,7 +222,7 @@ pub struct ClearChildren {
222222
}
223223

224224
impl Command for ClearChildren {
225-
fn write(self, world: &mut World) {
225+
fn apply(self, world: &mut World) {
226226
clear_children(self.parent, world);
227227
}
228228
}
@@ -234,7 +234,7 @@ pub struct ReplaceChildren {
234234
}
235235

236236
impl Command for ReplaceChildren {
237-
fn write(self, world: &mut World) {
237+
fn apply(self, world: &mut World) {
238238
clear_children(self.parent, world);
239239
world.entity_mut(self.parent).push_children(&self.children);
240240
}
@@ -247,7 +247,7 @@ pub struct RemoveParent {
247247
}
248248

249249
impl Command for RemoveParent {
250-
fn write(self, world: &mut World) {
250+
fn apply(self, world: &mut World) {
251251
world.entity_mut(self.child).remove_parent();
252252
}
253253
}

crates/bevy_hierarchy/src/hierarchy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn despawn_children_recursive(world: &mut World, entity: Entity) {
5555
}
5656

5757
impl Command for DespawnRecursive {
58-
fn write(self, world: &mut World) {
58+
fn apply(self, world: &mut World) {
5959
#[cfg(feature = "trace")]
6060
let _span = bevy_utils::tracing::info_span!(
6161
"command",
@@ -68,7 +68,7 @@ impl Command for DespawnRecursive {
6868
}
6969

7070
impl Command for DespawnChildrenRecursive {
71-
fn write(self, world: &mut World) {
71+
fn apply(self, world: &mut World) {
7272
#[cfg(feature = "trace")]
7373
let _span = bevy_utils::tracing::info_span!(
7474
"command",

crates/bevy_scene/src/scene_spawner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl SceneSpawner {
284284
parent,
285285
child: entity,
286286
}
287-
.write(world);
287+
.apply(world);
288288
}
289289
}
290290
} else {

crates/bevy_transform/src/commands.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ pub struct AddChildInPlace {
2121
pub child: Entity,
2222
}
2323
impl Command for AddChildInPlace {
24-
fn write(self, world: &mut World) {
24+
fn apply(self, world: &mut World) {
2525
let hierarchy_command = AddChild {
2626
child: self.child,
2727
parent: self.parent,
2828
};
29-
hierarchy_command.write(world);
29+
hierarchy_command.apply(world);
3030
// FIXME: Replace this closure with a `try` block. See: https://github.com/rust-lang/rust/issues/31436.
3131
let mut update_transform = || {
3232
let parent = *world.get_entity(self.parent)?.get::<GlobalTransform>()?;
@@ -49,9 +49,9 @@ pub struct RemoveParentInPlace {
4949
pub child: Entity,
5050
}
5151
impl Command for RemoveParentInPlace {
52-
fn write(self, world: &mut World) {
52+
fn apply(self, world: &mut World) {
5353
let hierarchy_command = RemoveParent { child: self.child };
54-
hierarchy_command.write(world);
54+
hierarchy_command.apply(world);
5555
// FIXME: Replace this closure with a `try` block. See: https://github.com/rust-lang/rust/issues/31436.
5656
let mut update_transform = || {
5757
let child_global = *world.get_entity(self.child)?.get::<GlobalTransform>()?;

0 commit comments

Comments
 (0)