Document panic condition

This commit is contained in:
BigWingBeat 2025-07-16 12:37:11 +01:00
parent c424288b7f
commit c8b1dccfe6
No known key found for this signature in database
GPG Key ID: 72F29AB570E9FEE5
2 changed files with 10 additions and 2 deletions

View File

@ -1550,6 +1550,11 @@ impl<'w> EntityWorldMut<'w> {
/// Temporarily removes the requested resource from the [`World`], runs custom user code,
/// then re-adds the resource before returning.
///
/// # Panics
///
/// Panics if the resource does not exist.
/// Use [`try_resource_scope`](Self::try_resource_scope) instead if you want to handle this case.
///
/// See [`World::resource_scope`] for further details.
#[track_caller]
pub fn resource_scope<R: Resource, U>(

View File

@ -2551,6 +2551,11 @@ impl World {
/// This enables safe simultaneous mutable access to both a resource and the rest of the [`World`].
/// For more complex access patterns, consider using [`SystemState`](crate::system::SystemState).
///
/// # Panics
///
/// Panics if the resource does not exist.
/// Use [`try_resource_scope`](Self::try_resource_scope) instead if you want to handle this case.
///
/// # Example
/// ```
/// use bevy_ecs::prelude::*;
@ -2568,8 +2573,6 @@ impl World {
/// });
/// assert_eq!(world.get_resource::<A>().unwrap().0, 2);
/// ```
///
/// See also [`try_resource_scope`](Self::try_resource_scope).
#[track_caller]
pub fn resource_scope<R: Resource, U>(&mut self, f: impl FnOnce(&mut World, Mut<R>) -> U) -> U {
self.try_resource_scope(f)