Take &mut self in `View::render`

Antonio Scandurra and Nathan Sobo created

Co-Authored-By: Nathan Sobo <nathan@zed.dev>

Change summary

gpui/examples/text.rs      |  2 +-
gpui/src/app.rs            | 36 ++++++++++++++++++------------------
gpui/src/elements/list.rs  |  2 +-
server/src/rpc.rs          |  2 +-
zed/src/chat_panel.rs      |  2 +-
zed/src/editor.rs          |  2 +-
zed/src/file_finder.rs     |  2 +-
zed/src/project_browser.rs |  2 +-
zed/src/theme_selector.rs  |  2 +-
zed/src/workspace.rs       |  2 +-
zed/src/workspace/pane.rs  |  2 +-
11 files changed, 28 insertions(+), 28 deletions(-)

Detailed changes

gpui/examples/text.rs 🔗

@@ -28,7 +28,7 @@ impl gpui::View for TextView {
         "View"
     }
 
-    fn render(&self, _: &mut gpui::RenderContext<Self>) -> gpui::ElementBox {
+    fn render(&mut self, _: &mut gpui::RenderContext<Self>) -> gpui::ElementBox {
         TextElement.boxed()
     }
 }

gpui/src/app.rs 🔗

@@ -40,7 +40,7 @@ pub trait Entity: 'static {
 
 pub trait View: Entity + Sized {
     fn ui_name() -> &'static str;
-    fn render(&self, cx: &mut RenderContext<'_, Self>) -> ElementBox;
+    fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox;
     fn on_focus(&mut self, _: &mut ViewContext<Self>) {}
     fn on_blur(&mut self, _: &mut ViewContext<Self>) {}
     fn keymap_context(&self, _: &AppContext) -> keymap::Context {
@@ -817,7 +817,7 @@ impl MutableAppContext {
         titlebar_height: f32,
         refreshing: bool,
     ) -> Result<ElementBox> {
-        let view = self
+        let mut view = self
             .cx
             .views
             .remove(&(window_id, view_id))
@@ -1863,7 +1863,7 @@ pub trait AnyView {
     fn release(&mut self, cx: &mut MutableAppContext);
     fn ui_name(&self) -> &'static str;
     fn render<'a>(
-        &self,
+        &mut self,
         window_id: usize,
         view_id: usize,
         titlebar_height: f32,
@@ -1896,7 +1896,7 @@ where
     }
 
     fn render<'a>(
-        &self,
+        &mut self,
         window_id: usize,
         view_id: usize,
         titlebar_height: f32,
@@ -3368,7 +3368,7 @@ mod tests {
         }
 
         impl super::View for View {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -3432,7 +3432,7 @@ mod tests {
         }
 
         impl super::View for View {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 let mouse_down_count = self.mouse_down_count.clone();
                 EventHandler::new(Empty::new().boxed())
                     .on_mouse_down(move |_| {
@@ -3494,7 +3494,7 @@ mod tests {
                 "View"
             }
 
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
         }
@@ -3534,7 +3534,7 @@ mod tests {
         }
 
         impl super::View for View {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -3590,7 +3590,7 @@ mod tests {
         }
 
         impl super::View for View {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -3640,7 +3640,7 @@ mod tests {
         }
 
         impl super::View for View {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -3684,7 +3684,7 @@ mod tests {
         }
 
         impl super::View for View {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -3731,7 +3731,7 @@ mod tests {
         }
 
         impl super::View for View {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -3789,7 +3789,7 @@ mod tests {
         }
 
         impl View for ViewA {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -3807,7 +3807,7 @@ mod tests {
         }
 
         impl View for ViewB {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -3903,7 +3903,7 @@ mod tests {
         }
 
         impl super::View for View {
-            fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
 
@@ -4038,7 +4038,7 @@ mod tests {
                 "test view"
             }
 
-            fn render(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
         }
@@ -4083,7 +4083,7 @@ mod tests {
                 "test view"
             }
 
-            fn render(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
         }
@@ -4106,7 +4106,7 @@ mod tests {
                 "test view"
             }
 
-            fn render(&self, _: &mut RenderContext<Self>) -> ElementBox {
+            fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
                 Empty::new().boxed()
             }
         }

gpui/src/elements/list.rs 🔗

@@ -510,7 +510,7 @@ mod tests {
             "TestView"
         }
 
-        fn render(&self, _: &mut RenderContext<'_, Self>) -> ElementBox {
+        fn render(&mut self, _: &mut RenderContext<'_, Self>) -> ElementBox {
             unimplemented!()
         }
     }

server/src/rpc.rs 🔗

@@ -1776,7 +1776,7 @@ mod tests {
             "empty view"
         }
 
-        fn render(&self, _: &mut gpui::RenderContext<Self>) -> gpui::ElementBox {
+        fn render(&mut self, _: &mut gpui::RenderContext<Self>) -> gpui::ElementBox {
             gpui::Element::boxed(gpui::elements::Empty)
         }
     }

zed/src/chat_panel.rs 🔗

@@ -220,7 +220,7 @@ impl View for ChatPanel {
         "ChatPanel"
     }
 
-    fn render(&self, cx: &mut RenderContext<Self>) -> ElementBox {
+    fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
         let theme = &self.settings.borrow().theme;
         Container::new(
             Flex::column()

zed/src/editor.rs 🔗

@@ -2522,7 +2522,7 @@ impl Entity for Editor {
 }
 
 impl View for Editor {
-    fn render<'a>(&self, _: &mut RenderContext<Self>) -> ElementBox {
+    fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
         EditorElement::new(self.handle.clone()).boxed()
     }
 

zed/src/file_finder.rs 🔗

@@ -79,7 +79,7 @@ impl View for FileFinder {
         "FileFinder"
     }
 
-    fn render(&self, _: &mut RenderContext<Self>) -> ElementBox {
+    fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
         let settings = self.settings.borrow();
 
         Align::new(

zed/src/project_browser.rs 🔗

@@ -13,7 +13,7 @@ impl View for ProjectBrowser {
         "ProjectBrowser"
     }
 
-    fn render(&self, _: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
+    fn render(&mut self, _: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
         Empty::new().boxed()
     }
 }

zed/src/theme_selector.rs 🔗

@@ -269,7 +269,7 @@ impl View for ThemeSelector {
         "ThemeSelector"
     }
 
-    fn render(&self, cx: &mut RenderContext<Self>) -> ElementBox {
+    fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
         let settings = self.settings.borrow();
 
         Align::new(

zed/src/workspace.rs 🔗

@@ -944,7 +944,7 @@ impl View for Workspace {
         "Workspace"
     }
 
-    fn render(&self, cx: &mut RenderContext<Self>) -> ElementBox {
+    fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
         let settings = self.settings.borrow();
         Container::new(
             Flex::column()

zed/src/workspace/pane.rs 🔗

@@ -369,7 +369,7 @@ impl View for Pane {
         "Pane"
     }
 
-    fn render(&self, cx: &mut RenderContext<Self>) -> ElementBox {
+    fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
         if let Some(active_item) = self.active_item() {
             Flex::column()
                 .with_child(self.render_tabs(cx))