bevy/examples/ecs
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
..
component_change_detection.rs Implement and require #[derive(Component)] on all component structs (#2254) 2021-10-03 19:23:44 +00:00
custom_query_param.rs Implement WorldQuery derive macro (#2713) 2022-02-24 00:19:49 +00:00
ecs_guide.rs Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
event.rs Simplify sending empty events (#2935) 2022-02-04 01:24:47 +00:00
fixed_timestep.rs Down with the system! (#2496) 2021-07-27 23:42:36 +00:00
generic_system.rs Add generic systems example (#2636) 2022-02-08 16:24:46 +00:00
hierarchy.rs Fix hierarchy example panic (#3378) 2021-12-20 20:33:38 +00:00
iter_combinations.rs Make the iter_combinators examples more pretty (#3075) 2022-01-06 19:13:52 +00:00
parallel_query.rs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
removal_detection.rs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
startup_system.rs Down with the system! (#2496) 2021-07-27 23:42:36 +00:00
state.rs Fix doc_markdown lints in examples (#3486) 2021-12-29 17:25:34 +00:00
system_chaining.rs Down with the system! (#2496) 2021-07-27 23:42:36 +00:00
system_param.rs Fix doc_markdown lints in examples (#3486) 2021-12-29 17:25:34 +00:00
system_sets.rs Deprecate .system (#3302) 2022-02-08 04:00:58 +00:00
timers.rs small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00