From b532235e38ef478e47ad9a9d8949a142dffe5e64 Mon Sep 17 00:00:00 2001 From: Ratys Date: Sat, 6 Feb 2021 22:52:36 +0300 Subject: [PATCH] `NonSend` documentation, minor error message fixes. --- crates/bevy_ecs/src/resource/resource_query.rs | 3 ++- crates/bevy_ecs/src/resource/resources.rs | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ecs/src/resource/resource_query.rs b/crates/bevy_ecs/src/resource/resource_query.rs index f97ba8b0506f2..6cd55a1d4a338 100644 --- a/crates/bevy_ecs/src/resource/resource_query.rs +++ b/crates/bevy_ecs/src/resource/resource_query.rs @@ -133,7 +133,8 @@ impl<'a, T: Resource + FromResources> DerefMut for Local<'a, T> { } } -// TODO: audit, document. +/// `NonSend` resources cannot leave the main thread, so any system that wants access to +/// a non-send resource will run on the main thread. See `Resources::insert_non_send()` and friends. #[derive(Debug)] pub struct NonSend<'a, T: Resource> { value: *mut T, diff --git a/crates/bevy_ecs/src/resource/resources.rs b/crates/bevy_ecs/src/resource/resources.rs index 9292e539e4c61..38123b09f63db 100644 --- a/crates/bevy_ecs/src/resource/resources.rs +++ b/crates/bevy_ecs/src/resource/resources.rs @@ -134,7 +134,7 @@ impl Resources { fn check_if_main_thread(&self) { if std::thread::current().id() != self.main_thread_id { - panic!("Attempted to access a thread local resource off of the main thread.") + panic!("Attempted to access a non-send resource off of the main thread.") } } @@ -282,7 +282,6 @@ impl Resources { .unwrap_or_else(|| panic!("Resource does not exist {}.", std::any::type_name::())) } - // TODO: audit. #[inline] #[allow(clippy::missing_safety_doc)] pub unsafe fn get_unsafe_non_send_ref(&self) -> NonNull { @@ -295,7 +294,7 @@ impl Resources { }) .unwrap_or_else(|| { panic!( - "Thread-local resource does not exist {}.", + "Non-send resource does not exist {}.", std::any::type_name::() ) })