File tree Expand file tree Collapse file tree 3 files changed +45
-32
lines changed Expand file tree Collapse file tree 3 files changed +45
-32
lines changed Original file line number Diff line number Diff line change 300
300
//! [`take`]: trait.Stream.html#method.take
301
301
//! [`min`]: trait.Stream.html#method.min
302
302
303
- pub use cycle:: { cycle, Cycle } ;
304
303
pub use empty:: { empty, Empty } ;
305
304
pub use from_fn:: { from_fn, FromFn } ;
306
305
pub use from_iter:: { from_iter, FromIter } ;
@@ -313,7 +312,6 @@ pub use stream::{
313
312
314
313
pub ( crate ) mod stream;
315
314
316
- mod cycle;
317
315
mod empty;
318
316
mod from_fn;
319
317
mod from_iter;
Original file line number Diff line number Diff line change @@ -22,6 +22,17 @@ enum CycleState {
22
22
FromBuffer ,
23
23
}
24
24
25
+ impl < T : Clone , S : Stream < Item = T > , > Cycle < S , T > {
26
+ pub fn new ( source : S ) -> Cycle < S , T > {
27
+ Cycle {
28
+ source,
29
+ index : 0 ,
30
+ buffer : Vec :: new ( ) ,
31
+ state : CycleState :: FromStream ,
32
+ }
33
+ }
34
+ }
35
+
25
36
impl < S , T > Stream for Cycle < S , T >
26
37
where
27
38
S : Stream < Item = T > ,
57
68
}
58
69
}
59
70
60
- /// Creats a stream that yields the provided values infinitely and in order.
61
- ///
62
- /// # Examples
63
- ///
64
- /// Basic usage:
65
- ///
66
- /// ```
67
- /// # async_std::task::block_on(async {
68
- /// #
69
- /// use async_std::prelude::*;
70
- /// use async_std::stream;
71
- ///
72
- /// let mut s = stream::cycle(stream::once(7));
73
- ///
74
- /// assert_eq!(s.next().await, Some(7));
75
- /// assert_eq!(s.next().await, Some(7));
76
- /// assert_eq!(s.next().await, Some(7));
77
- /// assert_eq!(s.next().await, Some(7));
78
- /// assert_eq!(s.next().await, Some(7));
79
- /// #
80
- /// # })
81
- /// ```
82
- pub fn cycle < S : Stream < Item = T > , T : Clone > ( source : S ) -> impl Stream < Item = S :: Item > {
83
- Cycle {
84
- source,
85
- index : 0 ,
86
- buffer : Vec :: new ( ) ,
87
- state : CycleState :: FromStream ,
88
- }
89
- }
Original file line number Diff line number Diff line change 24
24
mod all;
25
25
mod any;
26
26
mod chain;
27
+ mod cycle;
27
28
mod cmp;
28
29
mod cycle;
29
30
mod copied;
@@ -91,6 +92,7 @@ use partial_cmp::PartialCmpFuture;
91
92
use position:: PositionFuture ;
92
93
use try_fold:: TryFoldFuture ;
93
94
use try_for_each:: TryForEachFuture ;
95
+ use cycle:: Cycle ;
94
96
95
97
pub use chain:: Chain ;
96
98
pub use copied:: Copied ;
@@ -411,6 +413,38 @@ extension_trait! {
411
413
Copied :: new( self )
412
414
}
413
415
416
+ #[ doc = r#"
417
+ Creats a stream that yields the provided values infinitely and in order.
418
+
419
+ # Examples
420
+
421
+ Basic usage:
422
+
423
+ ```
424
+ # async_std::task::block_on(async {
425
+ #
426
+ use async_std::prelude::*;
427
+ use async_std::stream;
428
+
429
+ let mut s = stream::once(7).cycle();
430
+
431
+ assert_eq!(s.next().await, Some(7));
432
+ assert_eq!(s.next().await, Some(7));
433
+ assert_eq!(s.next().await, Some(7));
434
+ assert_eq!(s.next().await, Some(7));
435
+ assert_eq!(s.next().await, Some(7));
436
+ #
437
+ # })
438
+ ```
439
+ "# ]
440
+ fn cycle( self ) -> Cycle <Self , Self :: Item >
441
+ where
442
+ Self : Sized ,
443
+ Self :: Item : Clone ,
444
+ {
445
+ Cycle :: new( self )
446
+ }
447
+
414
448
#[ doc = r#"
415
449
Creates a stream that gives the current element's count as well as the next value.
416
450
You can’t perform that action at this time.
0 commit comments