make Plugin::build
consume the plugin
#1045
Closed
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.
This patch makes the
build
method of thePlugin
trait consume the plugin. This allows the plugin to transport non-clone-able configuration data into the build process of the plugin. Because this changes a core trait, it ends up touching a-lot, but in the vast majority of cases the change is just removing a&
fromself
in thebuild
method. It will break most users too, but the fix should in most if not all cases should just be removal of the&
fromself
in thebuild
method. It also changes the signature of the dynamically loaded plugin factory function slightly.The relevant changes, those not just fixing the signature, are in "crates/bevy_app/src/plugin.rs" and "crates/bevy_app/src/plugin_group.rs".
There are two instances in the existing code base that utilized the plugin to transport data into the build process, the
PrintDiagnosticsPlugin
and the examplePrintMessagePlugin
which no longer needed to clone the data and can instead just transfer ownership.My use case for this a precursor for one last alternate approach to overriding the
AssetIo
instance used in theAssetServer
. With this in place, it would be possible to implement overriding theAssetIo
like so:This patch is necessary for this approach to work since
AssetIo
does not, and should not, in my opinion, implementClone
.I don't know what future plans may be in store for the plugin system, so this might be taking things in the wrong direction.