Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IntoIterator instead of Vec for tabs #254

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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