Skip to content

Commit 769ce0f

Browse files
committed
Implement FromIterator<(AE, BE)> for (impl Default+Extend<AE>, impl Default+Extend<BE>)
1 parent 697f9ec commit 769ce0f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: core/src/iter/traits/collect.rs

+14
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ pub trait FromIterator<A>: Sized {
150150
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
151151
}
152152

153+
#[stable(feature = "from_iterator_for_tuple", since = "CURRENT_RUSTC_VERSION")]
154+
impl<A, B, AE, BE> FromIterator<(AE, BE)> for (A, B)
155+
where
156+
A: Default + Extend<AE>,
157+
B: Default + Extend<BE>,
158+
{
159+
fn from_iter<I: IntoIterator<Item = (AE, BE)>>(iter: I) -> Self {
160+
let mut res = <(A, B)>::default();
161+
res.extend(iter);
162+
163+
res
164+
}
165+
}
166+
153167
/// Conversion into an [`Iterator`].
154168
///
155169
/// By implementing `IntoIterator` for a type, you define how it will be

0 commit comments

Comments
 (0)