Skip to content

Commit c0a1801

Browse files
System-yeet for .run and friends
1 parent 82c0443 commit c0a1801

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

crates/bevy_ecs/src/system/function_system.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,52 @@ where
299299
}
300300
}
301301

302+
/// Allows end users to call system-running methods from the [`System`](crate::system::System) trait without .system().
303+
pub trait RunnableSystem<In, Out, Param: SystemParam, Marker>:
304+
IntoSystem<In, Out, (IsFunctionSystem, Param, Marker)>
305+
{
306+
fn apply_buffers(self, world: &mut World);
307+
308+
fn initialize(self, _world: &mut World);
309+
310+
fn run(self, input: In, world: &mut World) -> Out;
311+
312+
fn run_direct(self, input: In, world: &mut World) -> Out;
313+
}
314+
315+
impl<In, Out, Param: SystemParam, Marker, F> RunnableSystem<In, Out, Param, Marker> for F
316+
where
317+
In: 'static,
318+
Out: 'static,
319+
Param: SystemParam + 'static,
320+
Marker: 'static,
321+
F: SystemParamFunction<In, Out, Param, Marker>
322+
+ IntoSystem<
323+
In,
324+
Out,
325+
(IsFunctionSystem, Param, Marker),
326+
System = FunctionSystem<In, Out, Param, Marker, F>,
327+
> + Send
328+
+ Sync
329+
+ 'static,
330+
{
331+
fn apply_buffers(self, world: &mut World) {
332+
self.system().apply_buffers(world);
333+
}
334+
335+
fn initialize(self, world: &mut World) {
336+
self.system().initialize(world);
337+
}
338+
339+
fn run(self, input: In, world: &mut World) -> Out {
340+
self.system().run(input, world)
341+
}
342+
343+
fn run_direct(self, input: In, world: &mut World) -> Out {
344+
self.system().run_direct(input, world)
345+
}
346+
}
347+
302348
pub struct IsFunctionSystem;
303349

304350
impl<In, Out, Param, Marker, F> IntoSystem<In, Out, (IsFunctionSystem, Param, Marker)> for F
@@ -366,13 +412,17 @@ where
366412
#[inline]
367413
unsafe fn run_unsafe(&mut self, input: Self::In, world: &World) -> Self::Out {
368414
let change_tick = world.increment_change_tick();
369-
let out = self.func.run(
415+
// Trait disambiguation required here to disambiguate .run call
416+
// the .run found in the `RunnableSystem` trait
417+
let out = <F as SystemParamFunction<In, Out, Param, Marker>>::run(
418+
&mut self.func,
370419
input,
371420
self.param_state.as_mut().unwrap(),
372421
&self.system_meta,
373422
world,
374423
change_tick,
375424
);
425+
376426
self.system_meta.last_change_tick = change_tick;
377427
out
378428
}

crates/bevy_ecs/src/system/system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub trait System: Send + Sync + 'static {
8888
/// }
8989
///
9090
/// world.insert_resource::<Counter>(Counter(0));
91-
/// count_up.system().run_direct((), &mut world);
91+
/// count_up.run_direct((), &mut world);
9292
/// let counter = world.get_resource::<Counter>().unwrap();
9393
/// assert_eq!(counter.0, 1);
9494
/// ```

crates/bevy_ecs/src/world/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::{
1717
},
1818
entity::{Entities, Entity},
1919
query::{FilterFetch, QueryState, WorldQuery},
20-
schedule::{IntoSystemDescriptor, SystemDescriptor},
2120
storage::{Column, SparseSet, Storages},
2221
};
2322
use std::{

0 commit comments

Comments
 (0)