From 5c0c43cc7d3bdde301374365e2647737fcb6d495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bendeg=C3=BAz=20T=C3=B6r=C3=B6k?= <32034793+benditorok@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:47:51 +0100 Subject: [PATCH] Update macro (still unsafe) --- gears/src/macros.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gears/src/macros.rs b/gears/src/macros.rs index a087667..4dfd444 100644 --- a/gears/src/macros.rs +++ b/gears/src/macros.rs @@ -34,12 +34,20 @@ macro_rules! read_component { .map(|component| unsafe { std::mem::transmute::< std::sync::RwLockReadGuard<'_, $component>, - std::sync::RwLockReadGuard<'static, $component>, + std::sync::RwLockReadGuard<'_, $component>, >(component.read().unwrap()) }) }; } +/* +gears/src/ecs/mod.rs let component = Arc::clone(component); + unsafe { + // SAFETY: We ensure that the component is of type T + let component_ptr = Arc::into_raw(component) as *const RwLock; + Arc::from_raw(component_ptr) + } */ + /// A macro to aquire a write lock for component of an entity. #[macro_export] macro_rules! write_component { @@ -49,7 +57,7 @@ macro_rules! write_component { .map(|component| unsafe { std::mem::transmute::< std::sync::RwLockWriteGuard<'_, $component>, - std::sync::RwLockWriteGuard<'static, $component>, + std::sync::RwLockWriteGuard<'_, $component>, >(component.write().unwrap()) }) };