diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 8fbf102f38..4f86a23eff 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -158,10 +158,6 @@ pub trait UpgradeViewHandle { fn upgrade_any_view_handle(&self, handle: &AnyWeakViewHandle) -> Option; } -pub trait ReadView { - fn read_view(&self, handle: &ViewHandle) -> &T; -} - pub trait ReadViewWith { fn read_view_with( &self, @@ -1444,6 +1440,14 @@ impl AppContext { .unwrap() } + pub fn read_view(&self, handle: &ViewHandle) -> &T { + if let Some(view) = self.views.get(&(handle.window_id, handle.view_id)) { + view.as_any().downcast_ref().expect("downcast is type safe") + } else { + panic!("circular view reference for type {}", type_name::()); + } + } + fn remove_dropped_entities(&mut self) { loop { let (dropped_models, dropped_views, dropped_element_states) = @@ -2172,16 +2176,6 @@ impl UpgradeViewHandle for AppContext { } } -impl ReadView for AppContext { - fn read_view(&self, handle: &ViewHandle) -> &T { - if let Some(view) = self.views.get(&(handle.window_id, handle.view_id)) { - view.as_any().downcast_ref().expect("downcast is type safe") - } else { - panic!("circular view reference for type {}", type_name::()); - } - } -} - #[derive(Debug)] pub enum ParentId { View(usize), @@ -3488,12 +3482,6 @@ impl UpdateModel for ViewContext<'_, '_, V> { } } -impl ReadView for ViewContext<'_, '_, V> { - fn read_view(&self, handle: &ViewHandle) -> &T { - self.window_context.read_view(handle) - } -} - impl UpdateView for ViewContext<'_, '_, V> { type Output = S; @@ -3551,12 +3539,6 @@ impl UpdateModel for EventContext<'_, '_, '_, V> { } } -impl ReadView for EventContext<'_, '_, '_, V> { - fn read_view(&self, handle: &crate::ViewHandle) -> &W { - self.view_context.read_view(handle) - } -} - impl UpdateView for EventContext<'_, '_, '_, V> { type Output = S; @@ -3924,7 +3906,7 @@ impl ViewHandle { self.view_id } - pub fn read<'a, C: ReadView>(&self, cx: &'a C) -> &'a T { + pub fn read<'a>(&self, cx: &'a AppContext) -> &'a T { cx.read_view(self) } diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rs index 12dc9a60c5..a28507a095 100644 --- a/crates/gpui/src/app/window.rs +++ b/crates/gpui/src/app/window.rs @@ -15,9 +15,9 @@ use crate::{ util::post_inc, Action, AnyModelHandle, AnyView, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, AppContext, Effect, Element, Entity, Handle, ModelContext, ModelHandle, MouseRegion, - MouseRegionId, ParentId, ReadModel, ReadView, SceneBuilder, Subscription, UpdateModel, - UpdateView, UpgradeModelHandle, UpgradeViewHandle, View, ViewContext, ViewHandle, - WeakModelHandle, WeakViewHandle, WindowInvalidation, + MouseRegionId, ParentId, ReadModel, SceneBuilder, Subscription, UpdateModel, UpdateView, + UpgradeModelHandle, UpgradeViewHandle, View, ViewContext, ViewHandle, WeakModelHandle, + WeakViewHandle, WindowInvalidation, }; use anyhow::{anyhow, bail, Result}; use collections::{HashMap, HashSet}; @@ -149,12 +149,6 @@ impl UpdateModel for WindowContext<'_> { } } -impl ReadView for WindowContext<'_> { - fn read_view(&self, handle: &crate::ViewHandle) -> &W { - self.app_context.read_view(handle) - } -} - impl UpdateView for WindowContext<'_> { type Output = S;