Skip to content

Commit

Permalink
Use IntoIterator instead of Vec for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
barskern committed Jul 3, 2024
1 parent 6bbeba5 commit 26dfdef
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/widgets/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F>(
tabs: Vec<(TabId, TabLabel, Element<'a, Message, Theme, Renderer>)>,
tabs: impl IntoIterator<Item = (TabId, TabLabel, Element<'a, Message, Theme, Renderer>)>,
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));
Expand Down

0 comments on commit 26dfdef

Please sign in to comment.