bevy/examples/app
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
..
custom_loop.rs Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
drag_and_drop.rs Down with the system! (#2496) 2021-07-27 23:42:36 +00:00
empty_defaults.rs Merge AppBuilder into App (#2531) 2021-07-27 20:21:06 +00:00
empty.rs Merge AppBuilder into App (#2531) 2021-07-27 20:21:06 +00:00
headless_defaults.rs bevy_render: Use RenderDevice to get limits/features and expose AdapterInfo (#3931) 2022-02-16 21:17:37 +00:00
headless.rs Down with the system! (#2496) 2021-07-27 23:42:36 +00:00
logs.rs Down with the system! (#2496) 2021-07-27 23:42:36 +00:00
plugin_group.rs Fix doc_markdown lints in examples (#3486) 2021-12-29 17:25:34 +00:00
plugin.rs Down with the system! (#2496) 2021-07-27 23:42:36 +00:00
return_after_run.rs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
thread_pool_resources.rs Merge AppBuilder into App (#2531) 2021-07-27 20:21:06 +00:00
without_winit.rs Fix crash with disabled winit (#3330) 2021-12-15 00:15:47 +00:00