From 26dfdef76f42c06b8d07967dab52e6cb63135fc8 Mon Sep 17 00:00:00 2001 From: Ole Martin Ruud Date: Wed, 3 Jul 2024 14:07:01 +0200 Subject: [PATCH] Use IntoIterator instead of Vec for tabs --- src/widgets/tabs.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index 028b46fb..1362d7c0 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -115,15 +115,18 @@ where /// * the function that will be called if a tab is selected by the user. /// It takes the index of the selected tab. pub fn new_with_tabs( - tabs: Vec<(TabId, TabLabel, Element<'a, Message, Theme, Renderer>)>, + tabs: impl IntoIterator)>, on_select: F, ) -> Self where F: 'static + Fn(TabId) -> Message, { - let mut tab_labels = Vec::with_capacity(tabs.len()); - let mut elements = Vec::with_capacity(tabs.len()); - let mut indices = Vec::with_capacity(tabs.len()); + let tabs = tabs.into_iter(); + let n_tabs = tabs.size_hint().0; + + let mut tab_labels = Vec::with_capacity(n_tabs); + let mut elements = Vec::with_capacity(n_tabs); + let mut indices = Vec::with_capacity(n_tabs); for (id, tab_label, element) in tabs { tab_labels.push((id.clone(), tab_label));