-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Support StaticSystemInput in more places
#21916
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
Conversation
…erlying input type.
|
Would this work instead? |
Yeah, that would make We'd need to make the same change in a lot of places to make it work seamlessly everywhere, though, including |
|
I do think the approach of changing the call sites is better, but I won't block on this. I think this is a useful change! |
ItsDoot
left a comment
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.
Looks good, only thing I'd add is a test for a tuple of StaticSystemInputs and one for a mixed tuple of StaticSystemInput + a normal one.
|
I haven't done a full review yet, but if we go with this approach I'd like to bikeshed |
Yeah, if anyone has a good name, I'd be happy to update it! I usually use For a more brute-force approach, we could do something like Mostly I'm hoping that nobody needs to interact with this type very often, and that the doc comment mentioning
I added one test with a tuple of two |
alice-i-cecile
left a comment
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 you say more about the underlying user-facing motivation here? I want to be careful that we're not piling on complexity without good reason.
I think @ecoskey already answered this on Discord, but the goal is being able to write higher-order systems like In particular, I've always liked the " |
Could we just write a method to cast between the types? Seems like it should be something that is safe. |
Yeah, that should be possible! We could make a wrapper type with a manual That approach just feels awkward to me because you need to remember to call that method nearly every time you use |
|
I'm currently leaning towards #21917 over this, as it doesn't add an associated type. I plan to merge that and close this, unless one of y'all have a strong argument otherwise. |
Sounds good to me! I personally think associated types are simpler here, since they often don't need to be written out, but I acknowledge that it's entirely a matter of taste :). |
Objective
Let functions that take
StaticSystemInput<I>be used in APIs that requireIntoSystem<I, O, M>.Higher-order systems that are generic in their input type need to wrap their input in
StaticSystemInput. Unfortunately, that means they are not usable withWorld::run_system_cachedorSchedule::add_systems, since those requireIn = ()and notIn = StaticSystemInput<()>.Solution
Add an associated type
SystemInput::Underlyingthat is equal toSelf(up to lifetimes) for all input types other thanStaticSystemInput<I>, and equal toI::UnderlyingforStaticSystemInput<I>. Use that associated type for<FunctionSystem as System>::In.That means a function taking
StaticSystemInput<()>will be turned into a system withIn = ()instead ofIn = StaticSystemInput<()>, making it usable forWorld::run_system_cachedandSchedule::add_systems.Testing
Updated the doc example of a safe
PipeSystemto call the resulting system withWorld::run_system_cachedinstead of needing to callSystem::runexplicitly.Added unit tests passing a function taking
StaticSystemInput<()>toWorld::run_system_cachedandSchedule::add_systems.