-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
base: main
Are you sure you want to change the base?
Conversation
We've resisted similar things in the past ( |
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.
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 thetype_id
of the Box or the underlyingtype_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
!
impl<In, Out> System for Box<dyn System<In = In, Out = Out>> | ||
where | ||
In: SystemInput + 'static, | ||
Out: 'static, | ||
{ | ||
type In = In; | ||
type Out = Out; |
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.
Looking at impls for Box
in std
, it seems more common to make them generic in the contents of the box, like
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>
.
Objective
System
forBox<dyn System>
System
andReadOnlySystem
forBox<dyn System>
BoxedReadOnlySystem
type aliasSystem
forBox<dyn System>
#18624Solution
Testing
type_id
return thetype_id
of the Box or the underlyingtype_id
impl?