diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 1d50cfac9d591ac961fa0cd1ca1e07d72e128686..76b397fd22fe273570618a6af8065021f3230724 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -173,11 +173,13 @@ pub trait ReadViewWith { } pub trait UpdateView { + type Output; + fn update_view( &mut self, handle: &ViewHandle, update: &mut dyn FnMut(&mut T, &mut ViewContext) -> S, - ) -> S + ) -> Self::Output where T: View; } @@ -462,18 +464,19 @@ impl ReadModelWith for AsyncAppContext { } impl UpdateView for AsyncAppContext { + type Output = Option; + fn update_view( &mut self, handle: &ViewHandle, update: &mut dyn FnMut(&mut T, &mut ViewContext) -> S, - ) -> S + ) -> Option where T: View, { self.0 .borrow_mut() .update_window(handle.window_id, |cx| cx.update_view(handle, update)) - .unwrap() // TODO: is this unwrap safe? } } @@ -3472,6 +3475,8 @@ impl ReadView for ViewContext<'_, '_, '_, V> { } impl UpdateView for ViewContext<'_, '_, '_, V> { + type Output = S; + fn update_view( &mut self, handle: &ViewHandle, @@ -3533,6 +3538,8 @@ impl ReadView for EventContext<'_, '_, '_, '_, V> { } impl UpdateView for EventContext<'_, '_, '_, '_, V> { + type Output = S; + fn update_view( &mut self, handle: &ViewHandle, @@ -3913,7 +3920,7 @@ impl ViewHandle { }) } - pub fn update(&self, cx: &mut C, update: F) -> S + pub fn update(&self, cx: &mut C, update: F) -> C::Output where C: UpdateView, F: FnOnce(&mut T, &mut ViewContext) -> S, diff --git a/crates/gpui/src/app/test_app_context.rs b/crates/gpui/src/app/test_app_context.rs index ded009f4ba26574762041c18538ff278cdb5b3e4..5a367b15ba1a3ce38238f82df58d14d445604626 100644 --- a/crates/gpui/src/app/test_app_context.rs +++ b/crates/gpui/src/app/test_app_context.rs @@ -404,6 +404,8 @@ impl ReadModelWith for TestAppContext { } impl UpdateView for TestAppContext { + type Output = S; + fn update_view( &mut self, handle: &ViewHandle, diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rs index 4b053a8a09ec7c3ba3d26bea997007826d8a3b9b..3f01c14ddb7d58a8922cca5538b16370f5139080 100644 --- a/crates/gpui/src/app/window.rs +++ b/crates/gpui/src/app/window.rs @@ -155,6 +155,8 @@ impl ReadView for WindowContext<'_, '_> { } impl UpdateView for WindowContext<'_, '_> { + type Output = S; + fn update_view( &mut self, handle: &ViewHandle, @@ -172,7 +174,7 @@ impl UpdateView for WindowContext<'_, '_> { &mut cx, ) }) - .unwrap() // TODO: Is this unwrap safe? + .unwrap() } } diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 686c791691cf0a3d26e27e4c6f197f78766c09b4..788ea2ff64466b2097b04003fc553d6bc623fb79 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -823,6 +823,8 @@ mod tests { } impl<'a> UpdateView for DockTestContext<'a> { + type Output = S; + fn update_view( &mut self, handle: &ViewHandle, diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index c1840cf34f544e89bfe97358491954fbcc5d4037..889ee3987bb6abcca6822ecedd4f7e2501fb0343 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -467,7 +467,7 @@ impl ItemHandle for ViewHandle { workspace.project().clone(), cx, ) - }) + })? .await .log_err()?; Some(())