File tree Expand file tree Collapse file tree 3 files changed +46
-33
lines changed Expand file tree Collapse file tree 3 files changed +46
-33
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 enumerate;
29
30
mod eq;
@@ -86,6 +87,7 @@ use partial_cmp::PartialCmpFuture;
86
87
use position:: PositionFuture ;
87
88
use try_fold:: TryFoldFuture ;
88
89
use try_for_each:: TryForEachFuture ;
90
+ use cycle:: Cycle ;
89
91
90
92
pub use chain:: Chain ;
91
93
pub use filter:: Filter ;
@@ -369,6 +371,38 @@ extension_trait! {
369
371
Chain :: new( self , other)
370
372
}
371
373
374
+ #[ doc = r#"
375
+ Creats a stream that yields the provided values infinitely and in order.
376
+
377
+ # Examples
378
+
379
+ Basic usage:
380
+
381
+ ```
382
+ # async_std::task::block_on(async {
383
+ #
384
+ use async_std::prelude::*;
385
+ use async_std::stream;
386
+
387
+ let mut s = stream::once(7).cycle();
388
+
389
+ assert_eq!(s.next().await, Some(7));
390
+ assert_eq!(s.next().await, Some(7));
391
+ assert_eq!(s.next().await, Some(7));
392
+ assert_eq!(s.next().await, Some(7));
393
+ assert_eq!(s.next().await, Some(7));
394
+ #
395
+ # })
396
+ ```
397
+ "# ]
398
+ fn cycle( self ) -> Cycle <Self , Self :: Item >
399
+ where
400
+ Self : Sized ,
401
+ Self :: Item : Clone ,
402
+ {
403
+ Cycle :: new( self )
404
+ }
405
+
372
406
#[ doc = r#"
373
407
Creates a stream that gives the current element's count as well as the next value.
374
408
@@ -1590,7 +1624,7 @@ extension_trait! {
1590
1624
}
1591
1625
1592
1626
#[ doc = r#"
1593
- Searches for an element in a Stream that satisfies a predicate, returning
1627
+ Searches for an element in a Stream that satisfies a predicate, returning
1594
1628
its index.
1595
1629
1596
1630
# Examples
You can’t perform that action at this time.
0 commit comments