Skip to content

Commit

Permalink
Update macro (still unsafe)
Browse files Browse the repository at this point in the history
  • Loading branch information
benditorok committed Nov 26, 2024
1 parent 87a15c9 commit 5c0c43c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gears/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>;
Arc::from_raw(component_ptr)
} */

/// A macro to aquire a write lock for component of an entity.
#[macro_export]
macro_rules! write_component {
Expand All @@ -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())
})
};
Expand Down

0 comments on commit 5c0c43c

Please sign in to comment.