bevy/crates/bevy_window/src
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
..
cursor.rs Added set_cursor_icon(...) to Window (#3395) 2021-12-20 22:04:45 +00:00
event.rs Fix scale_factor_override in the winit backend (#2784) 2021-09-10 18:46:16 +00:00
lib.rs Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
raw_window_handle.rs fix clippy 2021-07-24 16:43:37 -07:00
system.rs Add EventWriter (#1575) 2021-03-07 20:42:04 +00:00
window.rs small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
windows.rs can change window settings at runtime (#644) 2020-10-15 11:42:19 -07:00