-
-
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
Simplify world schedule methods #8403
Conversation
So with the methods that take We should remove this footgun before removing the owned variants. One potential solution is this PR #7762. But I'm unsure if that PR is the right direction. |
Roping in @cart for this since this does have some major UX implications for the API. |
Is that not also true for |
So the footgun does exist for #[test]
fn test_boxed_label() {
use crate::{self as bevy_ecs, world::World};
#[derive(ScheduleLabel, Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
struct A;
let mut world = World::new();
world.add_schedule(Default::default(), A);
world
.try_run_schedule(Box::new(A) as BoxedScheduleLabel)
.unwrap(); // This returns `Err` since `Box::new(A) != A`
} I agree that we should fix this footgun but I don't think this PR is affected by it. |
I have a fix for the aforementioned footgun in #8436. |
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 think this is a net improvement, but I think in this case it may be worth it to make an API that can accept either the owned form or the reference using impl Deref
.
I would like to avoid the silly duplication though.
Having both was a UX decision. As a rule of thumb, we try to make as many user-facing label apis by-value as possible. It reads better, one less character to type, and the consistency across all label apis is nice. If someone is passing a label into a function, they can generally expect by value. The by-ref calls are almost always going to be "bevy internals code" (ex: retrieving an existing stored label and doing something with it). Users trying to run a schedule manually should not need to worry about references. I think it is worth it to make this by-value and then have the |
I took @alice-i-cecile's idea and made these methods take |
Great, I think that's a nice balance of pretty end user API and no code duplication. |
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.
Best of both worlds. Love it!
Objective
Methods for interacting with world schedules currently have two variants: one that takes
impl ScheduleLabel
and one that takes&dyn ScheduleLabel
. Operations such asrun_schedule
orschedule_scope
only use the label by reference, so there is little reason to have an owned variant of these functions.Solution
Decrease maintenance burden by merging the
ref
variants of these functions with the owned variants.Changelog
World::run_schedule_ref
. It is now redundant, sinceWorld::run_schedule
can take values by reference.Migration Guide
The method
World::run_schedule_ref
has been deprecated, and will be removed in the next version of Bevy. Userun_schedule
instead.