Skip to content

Implement System for Box<dyn System> #18625

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hankjordan
Copy link
Contributor

Objective

Solution

  • See above

Testing

  • Added module test
  • Should the implementation of type_id return the type_id of the Box or the underlying type_id impl?

@hankjordan hankjordan added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Mar 30, 2025
@alice-i-cecile alice-i-cecile added X-Contentious There are nontrivial implications that should be thought through S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 1, 2025
@alice-i-cecile
Copy link
Member

We've resisted similar things in the past (impl Reflect for Box<dyn Reflect>) out of concern for confusing double-boxing. I don't have a strong opinion on whether we should follow that precedent here, but I wanted to raise it.

Copy link
Contributor

@chescock chescock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've resisted similar things in the past (impl Reflect for Box<dyn Reflect>) out of concern for confusing double-boxing. I don't have a strong opinion on whether we should follow that precedent here, but I wanted to raise it.

I don't have a strong opinion here, either, but I can see how being able to use combinators like pipe with already-boxed systems could be useful.

  • Should the implementation of type_id return the type_id of the Box or the underlying type_id impl?

I'd vote for using the underlying impl, as you're doing now. After all, the whole point of that method is to get the actual type of a dyn System!

Comment on lines +222 to +228
impl<In, Out> System for Box<dyn System<In = In, Out = Out>>
where
In: SystemInput + 'static,
Out: 'static,
{
type In = In;
type Out = Out;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at impls for Box in std, it seems more common to make them generic in the contents of the box, like

Suggested change
impl<In, Out> System for Box<dyn System<In = In, Out = Out>>
where
In: SystemInput + 'static,
Out: 'static,
{
type In = In;
type Out = Out;
impl<S: System + ?Sized> System for Box<S> {
type In = S::In;
type Out = S::Out;

Then, since dyn System: System, that impl covers Box<dyn System>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement System for Box<dyn System>
3 participants