Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use Box instead of Rc for List event handlers
Max Brunsfelda208229a2ca6
diff --git a/crates/ui2/src/components/disclosure.rs b/crates/ui2/src/components/disclosure.rsindex 22cad27f583..7d9a69bb3a3 100644--- a/crates/ui2/src/components/disclosure.rs+++ b/crates/ui2/src/components/disclosure.rs@@ -1,14 +1,10 @@-use std::rc::Rc;-+use crate::{prelude::*, Color, Icon, IconButton, IconSize};use gpui::ClickEvent;-use crate::prelude::*;-use crate::{Color, Icon, IconButton, IconSize};-#[derive(IntoElement)]pub struct Disclosure {is_open: bool,- on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,+ on_toggle: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,}impl Disclosure {@@ -21,7 +17,7 @@ impl Disclosure {pub fn on_toggle(mut self,- handler: impl Into<Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>>,+ handler: impl Into<Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>>,) -> Self {self.on_toggle = handler.into();selfdiff --git a/crates/ui2/src/components/list/list_header.rs b/crates/ui2/src/components/list/list_header.rsindex 799b1c5dae8..933a1a95d7f 100644--- a/crates/ui2/src/components/list/list_header.rs+++ b/crates/ui2/src/components/list/list_header.rs@@ -1,18 +1,14 @@-use std::rc::Rc;-+use crate::{h_stack, prelude::*, Disclosure, Icon, IconElement, IconSize, Label};use gpui::{AnyElement, ClickEvent, Div};use smallvec::SmallVec;-use crate::prelude::*;-use crate::{h_stack, Disclosure, Icon, IconElement, IconSize, Label};-#[derive(IntoElement)]pub struct ListHeader {label: SharedString,left_icon: Option<Icon>,meta: SmallVec<[AnyElement; 2]>,toggle: Option<bool>,- on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,+ on_toggle: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,inset: bool,selected: bool,}@@ -39,7 +35,7 @@ impl ListHeader {mut self,on_toggle: impl Fn(&ClickEvent, &mut WindowContext) + 'static,) -> Self {- self.on_toggle = Some(Rc::new(on_toggle));+ self.on_toggle = Some(Box::new(on_toggle));self}diff --git a/crates/ui2/src/components/list/list_item.rs b/crates/ui2/src/components/list/list_item.rsindex 529f2c2a587..9db70c2ed21 100644--- a/crates/ui2/src/components/list/list_item.rs+++ b/crates/ui2/src/components/list/list_item.rs@@ -1,14 +1,10 @@-use std::rc::Rc;-+use crate::{prelude::*, Avatar, Disclosure, Icon, IconElement, IconSize};use gpui::{px, AnyElement, AnyView, ClickEvent, Div, ImageSource, MouseButton, MouseDownEvent, Pixels,Stateful,};use smallvec::SmallVec;-use crate::prelude::*;-use crate::{Avatar, Disclosure, Icon, IconElement, IconSize};-#[derive(IntoElement)]pub struct ListItem {id: ElementId,@@ -20,10 +16,10 @@ pub struct ListItem {left_slot: Option<AnyElement>,toggle: Option<bool>,inset: bool,- on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,- on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,+ on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,+ on_toggle: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>>,- on_secondary_mouse_down: Option<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,+ on_secondary_mouse_down: Option<Box<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,children: SmallVec<[AnyElement; 2]>,}@@ -46,7 +42,7 @@ impl ListItem {}pub fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self {- self.on_click = Some(Rc::new(handler));+ self.on_click = Some(Box::new(handler));self}@@ -54,7 +50,7 @@ impl ListItem {mut self,handler: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,) -> Self {- self.on_secondary_mouse_down = Some(Rc::new(handler));+ self.on_secondary_mouse_down = Some(Box::new(handler));self}@@ -87,7 +83,7 @@ impl ListItem {mut self,on_toggle: impl Fn(&ClickEvent, &mut WindowContext) + 'static,) -> Self {- self.on_toggle = Some(Rc::new(on_toggle));+ self.on_toggle = Some(Box::new(on_toggle));self}