From 7b5af57303d0b870959e8171240d8aa03bf0eec9 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 3 Apr 2024 17:48:54 +0000 Subject: [PATCH] Add docs for `FromIterator<(AE, BE)> for (A, B)` --- library/core/src/iter/traits/collect.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 788edfc3f8f9e..2ebbe2bf2743c 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -150,6 +150,25 @@ pub trait FromIterator: Sized { fn from_iter>(iter: T) -> Self; } +/// This implementation turns an iterator of tuples into a tuple of types which implement +/// [`Default`] and [`Extend`]. +/// +/// This is similar to [`Iterator::unzip`], but is also composable with other [`FromIterator`] +/// implementations: +/// +/// ```rust +/// # fn main() -> Result<(), core::num::ParseIntError> { +/// let string = "1,2,123,4"; +/// +/// let (numbers, lengths): (Vec<_>, Vec<_>) = string +/// .split(',') +/// .map(|s| s.parse().map(|n: u32| (n, s.len()))) +/// .collect::>()?; +/// +/// assert_eq!(numbers, [1, 2, 123, 4]); +/// assert_eq!(lengths, [1, 1, 3, 1]); +/// # Ok(()) } +/// ``` #[stable(feature = "from_iterator_for_tuple", since = "CURRENT_RUSTC_VERSION")] impl FromIterator<(AE, BE)> for (A, B) where