@@ -33,6 +33,10 @@ mod concat;
33
33
#[ allow( unreachable_pub) ] // https://github.com/rust-lang/rust/issues/57411
34
34
pub use self :: concat:: Concat ;
35
35
36
+ mod cycle;
37
+ #[ allow( unreachable_pub) ] // https://github.com/rust-lang/rust/issues/57411
38
+ pub use self :: cycle:: Cycle ;
39
+
36
40
mod enumerate;
37
41
#[ allow( unreachable_pub) ] // https://github.com/rust-lang/rust/issues/57411
38
42
pub use self :: enumerate:: Enumerate ;
@@ -513,6 +517,36 @@ pub trait StreamExt: Stream {
513
517
assert_future :: < Self :: Item , _ > ( Concat :: new ( self ) )
514
518
}
515
519
520
+ /// Repeats a stream endlessly.
521
+ ///
522
+ /// The stream never terminates. Note that you likely want to avoid
523
+ /// usage of `collect` or such on the returned stream as it will exhaust
524
+ /// available memory as it tries to just fill up all RAM.
525
+ ///
526
+ /// # Examples
527
+ ///
528
+ /// ```
529
+ /// # futures::executor::block_on(async {
530
+ /// use futures::stream::{self, StreamExt};
531
+ /// let a = [1, 2, 3];
532
+ /// let mut s = stream::iter(a.iter()).cycle();
533
+ ///
534
+ /// assert_eq!(s.next().await, Some(&1));
535
+ /// assert_eq!(s.next().await, Some(&2));
536
+ /// assert_eq!(s.next().await, Some(&3));
537
+ /// assert_eq!(s.next().await, Some(&1));
538
+ /// assert_eq!(s.next().await, Some(&2));
539
+ /// assert_eq!(s.next().await, Some(&3));
540
+ /// assert_eq!(s.next().await, Some(&1));
541
+ /// # });
542
+ /// ```
543
+ fn cycle ( self ) -> Cycle < Self >
544
+ where
545
+ Self : Sized + Clone ,
546
+ {
547
+ assert_stream :: < Self :: Item , _ > ( Cycle :: new ( self ) )
548
+ }
549
+
516
550
/// Execute an accumulating asynchronous computation over a stream,
517
551
/// collecting all the values into one final result.
518
552
///
0 commit comments