Skip to content

Deprecate panicking .resource methods #18084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/bevy_ecs/src/world/deferred_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ impl<'w> DeferredWorld<'w> {
/// Use [`get_resource_mut`](DeferredWorld::get_resource_mut) instead if you want to handle this case.
#[inline]
#[track_caller]
#[deprecated(
since = "0.16.0",
note = "Please use `get_resource_mut` instead, which returns an `Option` instead of panicking."
)]
pub fn resource_mut<R: Resource>(&mut self) -> Mut<'_, R> {
match self.get_resource_mut() {
Some(x) => x,
Expand Down Expand Up @@ -391,6 +395,10 @@ impl<'w> DeferredWorld<'w> {
/// This function will panic if it isn't called from the same thread that the resource was inserted from.
#[inline]
#[track_caller]
#[deprecated(
since = "0.16.0",
note = "Please use `get_non_send_resource_mut` instead, which returns an `Option` instead of panicking."
)]
pub fn non_send_resource_mut<R: 'static>(&mut self) -> Mut<'_, R> {
match self.get_non_send_resource_mut() {
Some(x) => x,
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,10 @@ impl<'w> EntityWorldMut<'w> {
///
/// Panics if the resource does not exist.
/// Use [`get_resource`](EntityWorldMut::get_resource) instead if you want to handle this case.
#[deprecated(
since = "0.16.0",
note = "Please use `get_resource` instead, which returns an `Option` instead of panicking."
)]
#[inline]
#[track_caller]
pub fn resource<R: Resource>(&self) -> &R {
Expand All @@ -1345,6 +1349,10 @@ impl<'w> EntityWorldMut<'w> {
/// use [`get_resource_or_insert_with`](World::get_resource_or_insert_with).
#[inline]
#[track_caller]
#[deprecated(
since = "0.16.0",
note = "Please use `get_resource_mut` instead, which returns an `Option` instead of panicking."
)]
pub fn resource_mut<R: Resource>(&mut self) -> Mut<'_, R> {
self.world.resource_mut::<R>()
}
Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,10 @@ impl World {
/// use [`get_resource_or_insert_with`](World::get_resource_or_insert_with).
#[inline]
#[track_caller]
#[deprecated(
since = "0.16.0",
note = "Please use `get_resource` instead, which returns an `Option` instead of panicking."
)]
pub fn resource<R: Resource>(&self) -> &R {
match self.get_resource() {
Some(x) => x,
Expand All @@ -1874,6 +1878,10 @@ impl World {
/// use [`get_resource_or_insert_with`](World::get_resource_or_insert_with).
#[inline]
#[track_caller]
#[deprecated(
since = "0.16.0",
note = "Please use `get_resource_ref` instead, which returns an `Option` instead of panicking."
)]
pub fn resource_ref<R: Resource>(&self) -> Ref<R> {
match self.get_resource_ref() {
Some(x) => x,
Expand All @@ -1898,6 +1906,10 @@ impl World {
/// use [`get_resource_or_insert_with`](World::get_resource_or_insert_with).
#[inline]
#[track_caller]
#[deprecated(
since = "0.16.0",
note = "Please use `get_resource_mut` instead, which returns an `Option` instead of panicking."
)]
pub fn resource_mut<R: Resource>(&mut self) -> Mut<'_, R> {
match self.get_resource_mut() {
Some(x) => x,
Expand Down
Loading