From 77e0e30f6faedadae3ff57f2b3abb0548a6a27f1 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 16 Aug 2024 19:30:06 +0200 Subject: fix(ecs): prevent nested queries causing panic --- ecs/src/util.rs | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) (limited to 'ecs/src/util.rs') diff --git a/ecs/src/util.rs b/ecs/src/util.rs index 5ec21c7..f4f8632 100644 --- a/ecs/src/util.rs +++ b/ecs/src/util.rs @@ -1,6 +1,3 @@ -use std::cell::Ref; -use std::ops::{Deref, DerefMut}; - pub trait Sortable { type Item; @@ -49,50 +46,3 @@ impl Sortable for Vec self.sort_by_key(func) } } - -#[derive(Debug)] -pub struct RefCellRefMap<'a, Value: 'a, MappedValue: 'a> -{ - mapped_value: MappedValue, - _refcell_ref: Ref<'a, Value>, -} - -impl<'a, Value: 'a, MappedValue: 'a> RefCellRefMap<'a, Value, MappedValue> -{ - pub fn new( - refcell_ref: Ref<'a, Value>, - map_fn: impl Fn(&'a Value) -> MappedValue, - ) -> Self - { - // Convert the lifetime to 'static. This is necessary to make the compiler not - // complain about refcell_ref being moved - // - // SAFETY: This is fine since we pass it to map_fn with the original lifetime 'a - let val_ref = unsafe { &*(&*refcell_ref as *const Value) }; - - let mapped_value = map_fn(val_ref); - - Self { - mapped_value, - _refcell_ref: refcell_ref, - } - } -} - -impl<'a, Value: 'a, MappedValue: 'a> Deref for RefCellRefMap<'a, Value, MappedValue> -{ - type Target = MappedValue; - - fn deref(&self) -> &Self::Target - { - &self.mapped_value - } -} - -impl<'a, Value: 'a, MappedValue: 'a> DerefMut for RefCellRefMap<'a, Value, MappedValue> -{ - fn deref_mut(&mut self) -> &mut Self::Target - { - &mut self.mapped_value - } -} -- cgit v1.2.3-18-g5258