Skip to content

Commit 407f957

Browse files
committed
Implement System::system_metas(&self) and System::system_metas_mut(&mut self)
for system exploration and configuration Part of #16168
1 parent c62c13d commit 407f957

File tree

5 files changed

+108
-3
lines changed

5 files changed

+108
-3
lines changed

crates/bevy_ecs/src/system/adapter_system.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use alloc::borrow::Cow;
22

3-
use super::{IntoSystem, ReadOnlySystem, System};
3+
use super::{IntoSystem, ReadOnlySystem, System, SystemMeta, SystemMetaProvider};
44
use crate::{
55
schedule::InternedSystemSet,
66
system::{input::SystemInput, SystemIn},
@@ -234,3 +234,21 @@ where
234234
self(run_system(input))
235235
}
236236
}
237+
238+
impl<Func, S> SystemMetaProvider for AdapterSystem<Func, S> {
239+
fn system_metas(&self) -> Vec<&SystemMeta> {
240+
todo!()
241+
}
242+
243+
fn system_metas_mut(&mut self) -> Vec<&mut SystemMeta> {
244+
todo!()
245+
}
246+
247+
fn extend_with_system_metas<'a>(&'a self, vec: &mut Vec<&'a SystemMeta>) {
248+
todo!()
249+
}
250+
251+
fn extend_with_system_metas_mut<'a>(&'a mut self, vec_mut: &mut Vec<&'a mut SystemMeta>) {
252+
todo!()
253+
}
254+
}

crates/bevy_ecs/src/system/combinator.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
world::unsafe_world_cell::UnsafeWorldCell,
1212
};
1313

14-
use super::{IntoSystem, ReadOnlySystem, System};
14+
use super::{IntoSystem, ReadOnlySystem, System, SystemMeta, SystemMetaProvider};
1515

1616
/// Customizes the behavior of a [`CombinatorSystem`].
1717
///
@@ -275,6 +275,24 @@ where
275275
}
276276
}
277277

278+
impl<Func, A, B> SystemMetaProvider for CombinatorSystem<Func, A, B> {
279+
fn system_metas(&self) -> Vec<&SystemMeta> {
280+
todo!()
281+
}
282+
283+
fn system_metas_mut(&mut self) -> Vec<&mut SystemMeta> {
284+
todo!()
285+
}
286+
287+
fn extend_with_system_metas<'a>(&'a self, vec: &mut Vec<&'a SystemMeta>) {
288+
todo!()
289+
}
290+
291+
fn extend_with_system_metas_mut<'a>(&'a mut self, vec_mut: &mut Vec<&'a mut SystemMeta>) {
292+
todo!()
293+
}
294+
}
295+
278296
/// An [`IntoSystem`] creating an instance of [`PipeSystem`].
279297
pub struct IntoPipeSystem<A, B> {
280298
a: A,

crates/bevy_ecs/src/system/exclusive_function_system.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use alloc::borrow::Cow;
1414
use bevy_utils::all_tuples;
1515
use core::marker::PhantomData;
1616

17+
use super::SystemMetaProvider;
18+
1719
/// A function system that runs with exclusive [`World`] access.
1820
///
1921
/// You get this by calling [`IntoSystem::into_system`] on a function that only accepts
@@ -186,6 +188,32 @@ where
186188
}
187189
}
188190

191+
impl<Marker, F> SystemMetaProvider for ExclusiveFunctionSystem<Marker, F>
192+
where
193+
Marker: 'static,
194+
F: ExclusiveSystemParamFunction<Marker>,
195+
{
196+
fn system_metas(&self) -> Vec<&SystemMeta> {
197+
let mut vec: Vec<&SystemMeta> = Vec::new();
198+
self.extend_with_system_metas(&mut vec);
199+
vec
200+
}
201+
202+
fn system_metas_mut(&mut self) -> Vec<&mut SystemMeta> {
203+
let mut vec: Vec<&mut SystemMeta> = Vec::new();
204+
self.extend_with_system_metas_mut(&mut vec);
205+
vec
206+
}
207+
208+
fn extend_with_system_metas<'a>(&'a self, vec: &mut Vec<&'a SystemMeta>) {
209+
vec.push(&self.system_meta);
210+
}
211+
212+
fn extend_with_system_metas_mut<'a>(&'a mut self, vec_mut: &mut Vec<&'a mut SystemMeta>) {
213+
vec_mut.push(&mut self.system_meta);
214+
}
215+
}
216+
189217
/// A trait implemented for all exclusive system functions that can be used as [`System`]s.
190218
///
191219
/// This trait can be useful for making your own systems which accept other systems,

crates/bevy_ecs/src/system/function_system.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ pub struct SystemMeta {
5050
pub(crate) commands_span: Span,
5151
}
5252

53+
/// Trait for retrieving system metas.
54+
pub trait SystemMetaProvider {
55+
/// Returns immutable references of system metas as a vector.
56+
fn system_metas(&self) -> Vec<&SystemMeta>;
57+
58+
/// Returns mutable references of system metas as a vector.
59+
fn system_metas_mut(&mut self) -> Vec<&mut SystemMeta>;
60+
61+
/// Helper method for `system_metas`.
62+
fn extend_with_system_metas<'a>(&'a self, vec: &mut Vec<&'a SystemMeta>);
63+
64+
/// Helper method for `system_metas_mut`.
65+
fn extend_with_system_metas_mut<'a>(&'a mut self, vec_mut: &mut Vec<&'a mut SystemMeta>);
66+
}
67+
5368
impl SystemMeta {
5469
pub(crate) fn new<T>() -> Self {
5570
let name = core::any::type_name::<T>();
@@ -826,6 +841,32 @@ where
826841
{
827842
}
828843

844+
impl<Marker, F> SystemMetaProvider for FunctionSystem<Marker, F>
845+
where
846+
Marker: 'static,
847+
F: SystemParamFunction<Marker>,
848+
{
849+
fn system_metas(&self) -> Vec<&SystemMeta> {
850+
let mut vec: Vec<&SystemMeta> = Vec::new();
851+
self.extend_with_system_metas(&mut vec);
852+
vec
853+
}
854+
855+
fn system_metas_mut(&mut self) -> Vec<&mut SystemMeta> {
856+
let mut vec: Vec<&mut SystemMeta> = Vec::new();
857+
self.extend_with_system_metas_mut(&mut vec);
858+
vec
859+
}
860+
861+
fn extend_with_system_metas<'a>(&'a self, vec: &mut Vec<&'a SystemMeta>) {
862+
vec.push(&self.system_meta);
863+
}
864+
865+
fn extend_with_system_metas_mut<'a>(&'a mut self, vec_mut: &mut Vec<&'a mut SystemMeta>) {
866+
vec_mut.push(&mut self.system_meta);
867+
}
868+
}
869+
829870
/// A trait implemented for all functions that can be used as [`System`]s.
830871
///
831872
/// This trait can be useful for making your own systems which accept other systems,

crates/bevy_ecs/src/system/system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
use alloc::borrow::Cow;
1515
use core::any::TypeId;
1616

17-
use super::IntoSystem;
17+
use super::{IntoSystem, SystemMeta};
1818

1919
/// An ECS system that can be added to a [`Schedule`](crate::schedule::Schedule)
2020
///

0 commit comments

Comments
 (0)