about summary refs log tree commit diff
path: root/src/libcore/iter
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-05-20 20:29:10 +0000
committerbors <bors@rust-lang.org>2018-05-20 20:29:10 +0000
commita1d4a9503e236b9f49cbdb23d00893201c117b2a (patch)
tree382d453bfea41fe090945975288cc647620b65a5 /src/libcore/iter
parent2dca249da08e059adf083171414a24d2c039b8cb (diff)
parenta74e1686d979fbf5688de549a9b2a951b1fb278f (diff)
Auto merge of #50234 - cramertj:extend, r=alexcrichton
Add implementation of Extend for ()

This is useful in some generic code which wants to collect iterators of items into a result.
Diffstat (limited to 'src/libcore/iter')
-rw-r--r--src/libcore/iter/traits.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs
index 173dfc36f04..1551429557f 100644
--- a/src/libcore/iter/traits.rs
+++ b/src/libcore/iter/traits.rs
@@ -352,6 +352,13 @@ pub trait Extend<A> {
     fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T);
 }
 
+#[stable(feature = "extend_for_unit", since = "1.28.0")]
+impl Extend<()> for () {
+    fn extend<T: IntoIterator<Item = ()>>(&mut self, iter: T) {
+        iter.into_iter().for_each(drop)
+    }
+}
+
 /// An iterator able to yield elements from both ends.
 ///
 /// Something that implements `DoubleEndedIterator` has one extra capability