Skip to content

Commit

Permalink
impl<T> FromIterator<T> for ()
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Feb 19, 2022
1 parent 2b42625 commit d1e444d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions library/core/src/unit.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::iter::FromIterator;

/// Collapses all unit items from an iterator into one.
/// Drains all items from an iterator.
///
/// This is more useful when combined with higher-level abstractions, like
/// collecting to a `Result<(), E>` where you only care about errors:
/// This is useful to run an iterator to completion when you don't
/// care about the result, or to collect into a `Result<(), E>` when
/// you only care about errors:
///
/// ```
/// use std::io::*;
Expand All @@ -14,8 +15,8 @@ use crate::iter::FromIterator;
/// assert!(res.is_ok());
/// ```
#[stable(feature = "unit_from_iter", since = "1.23.0")]
impl FromIterator<()> for () {
fn from_iter<I: IntoIterator<Item = ()>>(iter: I) -> Self {
iter.into_iter().for_each(|()| {})
impl<T> FromIterator<T> for () {
fn from_iter<A: IntoIterator<Item = T>>(iter: A) -> Self {
iter.into_iter().for_each(|_| {})
}
}

0 comments on commit d1e444d

Please sign in to comment.