Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
ui2: Clean up `drain`s
Marshall Bowers7b4a895ab9d1
diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rsindex e4494f46148..5155d700100 100644--- a/crates/ui2/src/components/chat_panel.rs+++ b/crates/ui2/src/components/chat_panel.rs@@ -22,7 +22,7 @@ impl ChatPanel {self}- fn render<S: 'static>(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {+ fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {div().id(self.element_id.clone()).flex()@@ -60,7 +60,7 @@ impl ChatPanel {.flex_col().gap_3().overflow_y_scroll()- .children(self.messages.drain(..)),+ .children(self.messages),)// Composer.child(div().flex().my_2().child(Input::new("Message #design"))),diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rsindex 3e0323d9422..206f5a2f31b 100644--- a/crates/ui2/src/components/context_menu.rs+++ b/crates/ui2/src/components/context_menu.rs@@ -42,7 +42,8 @@ impl ContextMenu {items: items.into_iter().collect(),}}- fn render<S: 'static>(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {++ fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {let theme = theme(cx);v_stack()@@ -53,7 +54,7 @@ impl ContextMenu {.child(List::new(self.items- .drain(..)+ .into_iter().map(ContextMenuItem::to_list_item).collect(),)diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rsindex 0bf413e2172..c629f6b89c3 100644--- a/crates/ui2/src/components/list.rs+++ b/crates/ui2/src/components/list.rs@@ -471,7 +471,7 @@ impl<S: 'static> ListDetailsEntry<S> {self}- fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {+ fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {let theme = theme(cx);let settings = user_settings(cx);@@ -504,14 +504,13 @@ impl<S: 'static> ListDetailsEntry<S> {.child(Label::new(self.label.clone()).color(label_color)).children(self.meta- .take().map(|meta| Label::new(meta).color(LabelColor::Muted)),).child(h_stack().gap_1().justify_end()- .children(self.actions.take().unwrap_or_default().into_iter()),+ .children(self.actions.unwrap_or_default()),)}}@@ -564,13 +563,13 @@ impl<S: 'static> List<S> {self}- fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {+ fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {let is_toggleable = self.toggleable != Toggleable::NotToggleable;let is_toggled = Toggleable::is_toggled(&self.toggleable);let list_content = match (self.items.is_empty(), is_toggled) {(_, false) => div(),- (false, _) => div().children(self.items.drain(..)),+ (false, _) => div().children(self.items),(true, _) => {div().child(Label::new(self.empty_message.clone()).color(LabelColor::Muted))}@@ -578,11 +577,7 @@ impl<S: 'static> List<S> {v_stack().py_1()- .children(- self.header- .take()- .map(|header| header.toggleable(self.toggleable)),- )+ .children(self.header.map(|header| header.toggleable(self.toggleable))).child(list_content)}}diff --git a/crates/ui2/src/components/modal.rs b/crates/ui2/src/components/modal.rsindex 2036c5df116..a83d1146886 100644--- a/crates/ui2/src/components/modal.rs+++ b/crates/ui2/src/components/modal.rs@@ -58,7 +58,7 @@ impl<S: 'static> Modal<S> {.child(div().children(self.title.clone().map(|t| Label::new(t)))).child(IconButton::new("close", Icon::Close)),)- .child(v_stack().p_1().children(self.children.drain(..)))+ .child(v_stack().p_1().children(self.children)).when(self.primary_action.is_some() || self.secondary_action.is_some(),|this| {diff --git a/crates/ui2/src/components/palette.rs b/crates/ui2/src/components/palette.rsindex 9f2da78a539..254afd94c42 100644--- a/crates/ui2/src/components/palette.rs+++ b/crates/ui2/src/components/palette.rs@@ -42,7 +42,7 @@ impl Palette {self}- fn render<S: 'static>(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {+ fn render<S: 'static>(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {let theme = theme(cx);v_stack()@@ -81,7 +81,7 @@ impl Palette {.into_iter().flatten(),)- .children(self.items.drain(..).enumerate().map(|(index, item)| {+ .children(self.items.into_iter().enumerate().map(|(index, item)| {h_stack().id(index).justify_between()diff --git a/crates/ui2/src/components/panel.rs b/crates/ui2/src/components/panel.rsindex a1a075a4b2f..861babf27ca 100644--- a/crates/ui2/src/components/panel.rs+++ b/crates/ui2/src/components/panel.rs@@ -92,7 +92,7 @@ impl<S: 'static> Panel<S> {self}- fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {+ fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {let theme = theme(cx);let current_size = self.width.unwrap_or(self.initial_width);@@ -113,7 +113,7 @@ impl<S: 'static> Panel<S> {}).bg(theme.surface).border_color(theme.border)- .children(self.children.drain(..))+ .children(self.children)}}diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rsindex a45de158bbb..b6928727419 100644--- a/crates/ui2/src/components/panes.rs+++ b/crates/ui2/src/components/panes.rs@@ -96,7 +96,7 @@ impl<V: 'static> PaneGroup<V> {}}- fn render(mut self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {+ fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {let theme = theme(cx);if !self.panes.is_empty() {@@ -106,7 +106,7 @@ impl<V: 'static> PaneGroup<V> {.gap_px().w_full().h_full()- .children(self.panes.drain(..).map(|pane| pane.render(view, cx)));+ .children(self.panes.into_iter().map(|pane| pane.render(view, cx)));if self.split_direction == SplitDirection::Horizontal {return el;@@ -123,7 +123,7 @@ impl<V: 'static> PaneGroup<V> {.w_full().h_full().bg(theme.editor)- .children(self.groups.drain(..).map(|group| group.render(view, cx)));+ .children(self.groups.into_iter().map(|group| group.render(view, cx)));if self.split_direction == SplitDirection::Horizontal {return el;diff --git a/crates/ui2/src/components/toolbar.rs b/crates/ui2/src/components/toolbar.rsindex e32697388e0..83bcde255eb 100644--- a/crates/ui2/src/components/toolbar.rs+++ b/crates/ui2/src/components/toolbar.rs@@ -54,7 +54,7 @@ impl<S: 'static> Toolbar<S> {self}- fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {+ fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {let theme = theme(cx);div()@@ -62,8 +62,8 @@ impl<S: 'static> Toolbar<S> {.p_2().flex().justify_between()- .child(div().flex().children(self.left_items.drain(..)))- .child(div().flex().children(self.right_items.drain(..)))+ .child(div().flex().children(self.left_items))+ .child(div().flex().children(self.right_items))}}