Skip to content

Commit

Permalink
document insert_non_send_resource panics (bevyengine#6328)
Browse files Browse the repository at this point in the history
Signed-off-by: Lena Milizé <me@lvmn.org>

# Objective

Fixes bevyengine#6277.

## Solution

Adds `# Panics` section to [`fn insert_non_send_resource`](http://dev-docs.bevyengine.org/bevy/ecs/world/struct.World.html#method.insert_non_send_resource) documentation, which explains that it panics when called from thread other than main thread.
  • Loading branch information
lovelymono authored and Pietrek14 committed Dec 17, 2022
1 parent 0f2805b commit ba58822
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ impl World {
/// The value given by the [`FromWorld::from_world`] method will be used.
/// Note that any resource with the `Default` trait automatically implements `FromWorld`,
/// and those default values will be here instead.
///
/// # Panics
///
/// Panics if called from a thread other than the main thread.
#[inline]
pub fn init_non_send_resource<R: 'static + FromWorld>(&mut self) {
if !self.contains_resource::<R>() {
Expand All @@ -763,6 +767,10 @@ impl World {
/// `NonSend` resources cannot be sent across threads,
/// and do not need the `Send + Sync` bounds.
/// Systems with `NonSend` resources are always scheduled on the main thread.
///
/// # Panics
///
/// Panics if called from a thread other than the main thread.
#[inline]
pub fn insert_non_send_resource<R: 'static>(&mut self, value: R) {
self.validate_non_send_access::<R>();
Expand Down

0 comments on commit ba58822

Please sign in to comment.