1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Generic `WorldOpCommand<F>` — collapses the boilerplate of "queue a
//! Bevy `Command` that runs with `&mut World`" used by every naia bevy
//! adapter Commands extension.
//!
//! Before this helper, every world-mutating Commands extension method
//! defined its own one-shot `Command` struct (e.g.
//! `ConfigureReplicationCommand`, `ReplicateResourceCommand`,
//! `RemoveReplicatedResourceCommand`, etc.) with the same shape:
//!
//! ```ignore
//! struct FooCommand { ... }
//! impl Command for FooCommand {
//! fn apply(self, world: &mut World) {
//! world.resource_scope(|world, mut server| { ... });
//! }
//! }
//! ```
//!
//! That's a lot of repeated structure for what is, in essence, "queue
//! this closure to run with `&mut World`." With `WorldOpCommand`:
//!
//! ```ignore
//! commands.queue(WorldOpCommand::new(move |world| {
//! world.resource_scope::<ServerImpl, _>(|world, mut server| { ... });
//! }));
//! ```
//!
//! Trade-off: the generic over `F` means each call site instantiates
//! its own concrete type. Small compile-time cost, big readability win
//! (no more per-operation Command struct + Command impl).
use Command;
use World;
/// A Bevy `Command` whose `apply` body is an arbitrary `FnOnce(&mut World)`.
///
/// Use this when you need to run code with `&mut World` deferred to the
/// next `apply_deferred` boundary. Saves the boilerplate of defining a
/// dedicated `Command` struct + impl per operation.