bevy/crates
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
..
bevy_app Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_asset Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_audio Update rodio 0.15 (#3846) 2022-02-03 04:25:44 +00:00
bevy_core Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_core_pipeline Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_crevice Don't panic in macro shape validation (#3647) 2022-01-15 22:14:43 +00:00
bevy_derive small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_diagnostic small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_dylib Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_dynamic_plugin Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_ecs Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_ecs_compile_fail_tests Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_gilrs Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_gltf Mesh vertex buffer layouts (#3959) 2022-02-23 23:21:13 +00:00
bevy_input Proper prehashing (#3963) 2022-02-18 03:26:01 +00:00
bevy_internal Internal Asset Hot Reloading (#3966) 2022-02-18 22:56:57 +00:00
bevy_log Implement init_resource for Commands and World (#3079) 2022-02-08 23:04:19 +00:00
bevy_macro_utils small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_math Release 0.6.0 (#3587) 2022-01-08 10:18:22 +00:00
bevy_pbr Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_reflect Updated visibility of reflected trait (#4034) 2022-02-25 07:05:51 +00:00
bevy_render Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_scene Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_sprite Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_tasks small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_text Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_transform small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
bevy_ui Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_utils Proper prehashing (#3963) 2022-02-18 03:26:01 +00:00
bevy_window Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bevy_winit Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00