@@ -22,7 +22,7 @@ use futures_task::{FutureObj, LocalFutureObj, LocalSpawn, Spawn, SpawnError};
2222mod abort;
2323
2424mod iter;
25- pub use self :: iter:: { Iter , IterMut , IterPinMut , IterPinRef } ;
25+ pub use self :: iter:: { IntoIter , Iter , IterMut , IterPinMut , IterPinRef } ;
2626
2727mod task;
2828use self :: task:: Task ;
@@ -194,10 +194,11 @@ impl<Fut> FuturesUnordered<Fut> {
194194 }
195195
196196 /// Returns an iterator that allows inspecting each future in the set.
197- fn iter_pin_ref ( self : Pin < & Self > ) -> IterPinRef < ' _ , Fut > {
197+ pub fn iter_pin_ref ( self : Pin < & Self > ) -> IterPinRef < ' _ , Fut > {
198198 let ( task, len) = self . atomic_load_head_and_len_all ( ) ;
199+ let pending_next_all = self . pending_next_all ( ) ;
199200
200- IterPinRef { task, len, pending_next_all : self . pending_next_all ( ) , _marker : PhantomData }
201+ IterPinRef { task, len, pending_next_all, _marker : PhantomData }
201202 }
202203
203204 /// Returns an iterator that allows modifying each future in the set.
@@ -581,6 +582,38 @@ impl<Fut> Drop for FuturesUnordered<Fut> {
581582 }
582583}
583584
585+ impl < ' a , Fut : Unpin > IntoIterator for & ' a FuturesUnordered < Fut > {
586+ type Item = & ' a Fut ;
587+ type IntoIter = Iter < ' a , Fut > ;
588+
589+ fn into_iter ( self ) -> Self :: IntoIter {
590+ self . iter ( )
591+ }
592+ }
593+
594+ impl < ' a , Fut : Unpin > IntoIterator for & ' a mut FuturesUnordered < Fut > {
595+ type Item = & ' a mut Fut ;
596+ type IntoIter = IterMut < ' a , Fut > ;
597+
598+ fn into_iter ( self ) -> Self :: IntoIter {
599+ self . iter_mut ( )
600+ }
601+ }
602+
603+ impl < Fut : Unpin > IntoIterator for FuturesUnordered < Fut > {
604+ type Item = Fut ;
605+ type IntoIter = IntoIter < Fut > ;
606+
607+ fn into_iter ( mut self ) -> Self :: IntoIter {
608+ // `head_all` can be accessed directly and we don't need to spin on
609+ // `Task::next_all` since we have exclusive access to the set.
610+ let task = * self . head_all . get_mut ( ) ;
611+ let len = if task. is_null ( ) { 0 } else { unsafe { * ( * task) . len_all . get ( ) } } ;
612+
613+ IntoIter { len, inner : self }
614+ }
615+ }
616+
584617impl < Fut > FromIterator < Fut > for FuturesUnordered < Fut > {
585618 fn from_iter < I > ( iter : I ) -> Self
586619 where
0 commit comments