about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2024-04-03 17:48:54 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2024-04-03 17:48:54 +0000
commit7b5af57303d0b870959e8171240d8aa03bf0eec9 (patch)
tree02c171e6c54f46d4a21c586b52f738a313e7dc9e
parent03862a553839ad51c24bad8e6742eb1fb2612817 (diff)
downloadrust-7b5af57303d0b870959e8171240d8aa03bf0eec9.tar.gz
rust-7b5af57303d0b870959e8171240d8aa03bf0eec9.zip
Add docs for `FromIterator<(AE, BE)> for (A, B)`
-rw-r--r--library/core/src/iter/traits/collect.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs
index 788edfc3f8f..2ebbe2bf274 100644
--- a/library/core/src/iter/traits/collect.rs
+++ b/library/core/src/iter/traits/collect.rs
@@ -150,6 +150,25 @@ pub trait FromIterator<A>: Sized {
     fn from_iter<T: IntoIterator<Item = A>>(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::<Result<_, _>>()?;
+///
+/// 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<A, B, AE, BE> FromIterator<(AE, BE)> for (A, B)
 where