Skip to content

Commit

Permalink
Add docs for FromIterator<(AE, BE)> for (A, B)
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Apr 3, 2024
1 parent 03862a5 commit 7b5af57
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 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,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
Expand Down

0 comments on commit 7b5af57

Please sign in to comment.