Skip to content

Commit

Permalink
Implement FromIterator<(AE, BE)> for `(impl Default+Extend<AE>, imp…
Browse files Browse the repository at this point in the history
…l Default+Extend<BE>)`
  • Loading branch information
WaffleLapkin committed Apr 3, 2024
1 parent 029cb1b commit 03862a5
Showing 1 changed file with 14 additions and 0 deletions.
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

0 comments on commit 03862a5

Please sign in to comment.