From 9f9137cf766809adb1f6f62b9d1c74258de933a8 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 24 Oct 2023 15:12:51 +0200 Subject: [PATCH] Remove failed attempt at eliminating static bounds on entities --- crates/gpui2/src/app/entity_map.rs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs index b593fd3745..9c1ac07ad3 100644 --- a/crates/gpui2/src/app/entity_map.rs +++ b/crates/gpui2/src/app/entity_map.rs @@ -86,8 +86,8 @@ impl EntityMap { .insert(lease.handle.entity_id, lease.entity.take().unwrap()); } - pub fn read(&self, handle: &Handle) -> &T { - (handle.downcast_entity)(&self.entities[handle.entity_id]) + pub fn read(&self, handle: &Handle) -> &T { + self.entities[handle.entity_id].downcast_ref().unwrap() } pub fn take_dropped(&mut self) -> Vec<(EntityId, AnyBox)> { @@ -105,17 +105,17 @@ pub struct Lease<'a, T> { entity_type: PhantomData, } -impl<'a, T> core::ops::Deref for Lease<'a, T> { +impl<'a, T: 'static> core::ops::Deref for Lease<'a, T> { type Target = T; fn deref(&self) -> &Self::Target { - (self.handle.downcast_entity)(self.entity.as_ref().unwrap()) + self.entity.as_ref().unwrap().downcast_ref().unwrap() } } -impl<'a, T> core::ops::DerefMut for Lease<'a, T> { +impl<'a, T: 'static> core::ops::DerefMut for Lease<'a, T> { fn deref_mut(&mut self) -> &mut Self::Target { - (self.handle.downcast_entity_mut)(self.entity.as_mut().unwrap()) + self.entity.as_mut().unwrap().downcast_mut().unwrap() } } @@ -163,8 +163,6 @@ impl AnyHandle { Some(Handle { any_handle: self.clone(), entity_type: PhantomData, - downcast_entity: |any| any.downcast_ref().unwrap(), - downcast_entity_mut: |any| any.downcast_mut().unwrap(), }) } else { None @@ -238,8 +236,6 @@ pub struct Handle { #[deref_mut] any_handle: AnyHandle, entity_type: PhantomData, - downcast_entity: fn(&dyn Any) -> &T, - downcast_entity_mut: fn(&mut dyn Any) -> &mut T, } unsafe impl Send for Handle {} @@ -253,8 +249,6 @@ impl Handle { Self { any_handle: AnyHandle::new(id, TypeId::of::(), entity_map), entity_type: PhantomData, - downcast_entity: |any| any.downcast_ref().unwrap(), - downcast_entity_mut: |any| any.downcast_mut().unwrap(), } } @@ -262,8 +256,6 @@ impl Handle { WeakHandle { any_handle: self.any_handle.downgrade(), entity_type: self.entity_type, - downcast_entity: self.downcast_entity, - downcast_entity_mut: self.downcast_entity_mut, } } @@ -293,8 +285,6 @@ impl Clone for Handle { Self { any_handle: self.any_handle.clone(), entity_type: self.entity_type, - downcast_entity: self.downcast_entity, - downcast_entity_mut: self.downcast_entity_mut, } } } @@ -386,8 +376,6 @@ pub struct WeakHandle { #[deref_mut] any_handle: AnyWeakHandle, entity_type: PhantomData, - downcast_entity: fn(&dyn Any) -> &T, - pub(crate) downcast_entity_mut: fn(&mut dyn Any) -> &mut T, } unsafe impl Send for WeakHandle {} @@ -398,8 +386,6 @@ impl Clone for WeakHandle { Self { any_handle: self.any_handle.clone(), entity_type: self.entity_type, - downcast_entity: self.downcast_entity, - downcast_entity_mut: self.downcast_entity_mut, } } } @@ -409,8 +395,6 @@ impl WeakHandle { Some(Handle { any_handle: self.any_handle.upgrade()?, entity_type: self.entity_type, - downcast_entity: self.downcast_entity, - downcast_entity_mut: self.downcast_entity_mut, }) }