Better ergonomics for WorldBorrow[Mut] API#7408
Closed
ruifengx wants to merge 2 commits intobevyengine:mainfrom
ruifengx:main
Closed
Better ergonomics for WorldBorrow[Mut] API#7408ruifengx wants to merge 2 commits intobevyengine:mainfrom ruifengx:main
WorldBorrow[Mut] API#7408ruifengx wants to merge 2 commits intobevyengine:mainfrom
ruifengx:main
Conversation
Contributor
|
WorldCell was removed in #12551, visit the linked PR for the rationale. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
WorldBorrow[Mut]<T>toWorldBorrow[Mut]<U>WorldBorrow<T>Consider the following example:
Previously it is very complicated to define the two accessor functions, because
&[u32]must outlive theWorldBorrow<SomeResource>, and we have to e.g. return a wrapper aroundWorldBorrow<SomeResource>implementingDeref<[u16]>.Now that we have two functions consuming
WorldBorrows, it might also be desirable to keep the original borrow by cloning it beforehand. Therefore we implementCloneforWorldBorrow<T>.Solution
mapandtry_mapconsumesselfand moves the witness of borrow.clonesimply borrows the data again from the same world.Unresolved Questions
mapandtry_mapare introduced as functions instead of inherent methodsMut::map_unchangedis already an inherent method, so there is an inconsistencyChangelog
mapandtry_mapforWorldBorrowandWorldBorrowMutCloneforWorldBorrowTechnically this will break downstream code because
borrow.clone()is now ambiguousMigration Guide
WorldBorrow<T>now implementsClone. If you have code cloning the inner value behind aWorldBorrow:You need to explicitly dereference the borrow to clone the inner value:
Now you may also clone the borrow itself: