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

Implement FromIterator for (impl Default + Extend, impl Default + Extend) #107462

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Changes from 1 commit
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
Next Next commit
Implement FromIterator<(AE, BE)> for `(impl Default+Extend<AE>, imp…
…l Default+Extend<BE>)`
  • Loading branch information
WaffleLapkin committed Apr 3, 2024
commit 03862a553839ad51c24bad8e6742eb1fb2612817
14 changes: 14 additions & 0 deletions library/core/src/iter/traits/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ pub trait FromIterator<A>: Sized {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
}

#[stable(feature = "from_iterator_for_tuple", since = "CURRENT_RUSTC_VERSION")]
impl<A, B, AE, BE> FromIterator<(AE, BE)> for (A, B)
where
A: Default + Extend<AE>,
B: Default + Extend<BE>,
{
fn from_iter<I: IntoIterator<Item = (AE, BE)>>(iter: I) -> Self {
let mut res = <(A, B)>::default();
res.extend(iter);

res
}
}

/// Conversion into an [`Iterator`].
///
/// By implementing `IntoIterator` for a type, you define how it will be
Expand Down
Loading