-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
World::get_resource_or_init
as an alternative to `World::get_re…
…source_or_insert_with` (#15758) # Objective If a `Resource` implements `FromWorld` or `Default`, it's nicer to be able to write: ```rust let foo = world.get_resource_or_init::<Foo>(); ``` Rather than: ```rust let foo = world.get_resource_or_insert_with(Foo::default); ``` The latter is also not possible if a type implements `FromWorld` only, and not `Default`. ## Solution Added: ```rust impl World { pub fn get_resource_or_init<R: Resource + FromWorld>(&mut self) -> Mut<'_, R>; } ``` Turns out all current in-engine uses of `get_resource_or_insert_with` are exactly the above, so they've also been replaced. ## Testing - Added a doc-test. - Also added a doc-test for `World::get_resource_or_insert_with`.
- Loading branch information
Showing
6 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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