-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement System::system_metas(&self)
and System::system_metas_mut(&mut self)
for system exploration and configuration
#16275
base: main
Are you sure you want to change the base?
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
@alice-i-cecile |
@MiniaczQ, opinions? |
In all of the cases other than for piped systems, this method should return a vector with one element :) |
Yeah, I didn't want to tackle this, because it's actually pretty technical. Step 1We definitely need a trait that has Now, to make this actually work, we need another set of methods (in that trait): Step 2Then there is the matter of in-lining it. let mut my_system = IntoSystem::into_system(my_system);
my_system.system_metas_mut()[0].name = "abba".into();
app.add_systems(Update, my_system); so we want a app.add_systems(Update, my_system.map_system_metas(|metas| { metas[0].name = "abba".into(); })); no need for immutable variant. Step 3Sadly this isn't the end for this issue, we also should expose |
Thanks for the detailed overview :) |
a43457b
to
407f957
Compare
@MiniaczQ
|
Looks good! |
53059ae
to
c1b7131
Compare
…(&mut self)` for system exploration and configuration Part of bevyengine#16168
c1b7131
to
aac8a2e
Compare
Done with non-primitive systems, if this looks fine we can work with the next steps. |
fn system_metas_mut(&mut self) -> Vec<&mut SystemMeta>; | ||
|
||
/// Helper method for `system_metas`. | ||
fn extend_with_system_metas<'a>(&'a self, vec: &mut Vec<&'a SystemMeta>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be better for these to take an impl Extend
instead of a Vec. https://doc.rust-lang.org/core/iter/trait.Extend.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's neat, but I don't think it's appropriate to implement it here
Unless I don't understand your point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was saying to change the function signature to fn extend_with_system_metas<'a>(&'a self, extendable: impl Extend<&'a SystemMeta>)
, which would allow the methods to take a bunch of the other std collections and not be limited to just a Vec
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely missed the point then :)
I'm down for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to take impl FnMut(&'a SystemMeta)
. That way, users that are just going to iterate over the result won't even have to allocate a Vec
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you recommend going with extend first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, my point was that FnOnce
is more general than Extend
here. You'd still offer the version that returns a Vec
!
fn for_each_system_meta<'a>(&'a self, f: impl FnOnce(&'a SystemMeta));
fn system_metas(&self) -> Vec<&SystemMeta> {
let mut result = Vec::new();
self.for_each_system_meta(|meta| result.push(meta));
result
}
If someone wants to populate another type of collection, they can pass a closure that calls the relevant push
method. But if they were just going to do for meta in system.system_metas() { ... }
then they can avoid an allocation by calling system.for_each_system_meta(|meta| ...)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't be FnOnce
since we use it many times, besides that makes sense, I voice no preference then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea seems reasonable.
Part of #16168
Objective
Implement
System::system_metas(&self)
andSystem::system_metas_mut(&mut self)
for system exploration and configuration.Solution
Introduce System::system_metas(&self) and System::system_metas_mut(&mut self) which would return iterator/vector/slice that we can work with.