Add with_cloned_input and WithClonedInputWrapper to system functionality
#22154
+123
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
I didn't see an issue for something like this made yet, but I ran into a particularly non-ergonomic situation when working on a prototype where I wanted to be able to run a system that normally takes owned input via
Inwith a static, cloneable value. Thewith_inputandwith_input_fromfunctions both require the system takes a mutable reference to their input types, so they wouldn't work for my general case.Solution
I effectively copied the code from the
WithInputWrapperandWithInputFromWrapperstructs and modified it slightly so that itclones the contained value and passes it as input to the wrapped system.Testing
The project successfully builds on my machine, and my personal game prototype was built and ran successfully using this extra functionality. Totally possible I missed an edge case though.
Showcase
The idea being that I want to use
spawn_creaturesomewhere else with dynamic input, usingrun_system_cached_with, but on some schedule (in this case,Startup), I want to give it a constant input.