From 7b4a895ab9d16ba7ab51f5568238efae32fe4c29 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 15:41:29 +0200 Subject: [PATCH] ui2: Clean up `drain`s --- crates/ui2/src/components/chat_panel.rs | 4 ++-- crates/ui2/src/components/context_menu.rs | 5 +++-- crates/ui2/src/components/list.rs | 15 +++++---------- crates/ui2/src/components/modal.rs | 2 +- crates/ui2/src/components/palette.rs | 4 ++-- crates/ui2/src/components/panel.rs | 4 ++-- crates/ui2/src/components/panes.rs | 6 +++--- crates/ui2/src/components/toolbar.rs | 6 +++--- 8 files changed, 21 insertions(+), 25 deletions(-) diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index e4494f461487365187aed31839a455bf38d655a5..5155d700100eece00457bea8f9170654327a995e 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(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { 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.rs index 3e0323d9422af69bf5b204ca935d9756a160f5e9..206f5a2f31b8996907efcc8d2203d93676e5e9b3 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(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { 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.rs index 0bf413e2172654db6b2828cc383928ec05fa6499..c629f6b89c39ea0bbe4499bcba55a4055bcfa209 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -471,7 +471,7 @@ impl ListDetailsEntry { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let settings = user_settings(cx); @@ -504,14 +504,13 @@ impl ListDetailsEntry { .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 List { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { 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 List { 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.rs index 2036c5df116019321b4a7225ca464a810e73e97a..a83d11468864706ca1328ed4df6d8017285eba23 100644 --- a/crates/ui2/src/components/modal.rs +++ b/crates/ui2/src/components/modal.rs @@ -58,7 +58,7 @@ impl Modal { .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.rs index 9f2da78a53942a49c4eea0130efac740f3c033b9..254afd94c42f553f946ea3b08b197fde4e624fa1 100644 --- a/crates/ui2/src/components/palette.rs +++ b/crates/ui2/src/components/palette.rs @@ -42,7 +42,7 @@ impl Palette { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { 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.rs index a1a075a4b2f1a81468137ec9964630fc897b7d55..861babf27ca6cba09734859f8979f93ea5b01ea7 100644 --- a/crates/ui2/src/components/panel.rs +++ b/crates/ui2/src/components/panel.rs @@ -92,7 +92,7 @@ impl Panel { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let current_size = self.width.unwrap_or(self.initial_width); @@ -113,7 +113,7 @@ impl Panel { }) .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.rs index a45de158bbbb133d3cc910fa244f8f3784d84997..b692872741948f01566bb8012227f9f42d9b4727 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -96,7 +96,7 @@ impl PaneGroup { } } - fn render(mut self, view: &mut V, cx: &mut ViewContext) -> impl Component { + fn render(self, view: &mut V, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); if !self.panes.is_empty() { @@ -106,7 +106,7 @@ impl PaneGroup { .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 PaneGroup { .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.rs index e32697388e0d24908e3e8aa18409701b7fddf0b7..83bcde255eb4fd973717ed84c0f15aca5887532d 100644 --- a/crates/ui2/src/components/toolbar.rs +++ b/crates/ui2/src/components/toolbar.rs @@ -54,7 +54,7 @@ impl Toolbar { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -62,8 +62,8 @@ impl Toolbar { .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)) } }