bevy/examples/2d
Alice Cecile 557ab9897a Make get_resource (and friends) infallible (#4047)
# Objective

- In the large majority of cases, users were calling `.unwrap()` immediately after `.get_resource`.
- Attempting to add more helpful error messages here resulted in endless manual boilerplate (see #3899 and the linked PRs).

## Solution

- Add an infallible variant named `.resource` and so on.
- Use these infallible variants over `.get_resource().unwrap()` across the code base.

## Notes

I did not provide equivalent methods on `WorldCell`, in favor of removing it entirely in #3939.

## Migration Guide

Infallible variants of `.get_resource` have been added that implicitly panic, rather than needing to be unwrapped.

Replace `world.get_resource::<Foo>().unwrap()` with `world.resource::<Foo>()`.

## Impact

- `.unwrap` search results before: 1084
- `.unwrap` search results after: 942
- internal `unwrap_or_else` calls added: 4
- trivial unwrap calls removed from tests and code: 146
- uses of the new `try_get_resource` API: 11
- percentage of the time the unwrapping API was used internally: 93%
2022-02-27 22:37:18 +00:00
..
contributors.rs Cleanup some things which shouldn't be components (#2982) 2022-02-03 23:56:57 +00:00
many_sprites.rs small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
mesh2d_manual.rs Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
mesh2d.rs Add 2d meshes and materials (#3460) 2022-01-08 01:29:08 +00:00
move_sprite.rs Add move sprite example. (#2414) 2022-02-02 02:44:51 +00:00
rect.rs Add an example to draw a rectangle (#2957) 2021-12-18 00:52:37 +00:00
rotation.rs Simple 2d rotation example (#3065) 2022-01-25 22:10:11 +00:00
sprite_flipping.rs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
sprite_sheet.rs Cleanup some things which shouldn't be components (#2982) 2022-02-03 23:56:57 +00:00
sprite.rs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
text2d.rs Implement and require #[derive(Component)] on all component structs (#2254) 2021-10-03 19:23:44 +00:00
texture_atlas.rs small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00