24
24
mod all;
25
25
mod any;
26
26
mod chain;
27
+ mod cloned;
27
28
mod cmp;
28
29
mod copied;
29
30
mod enumerate;
@@ -91,6 +92,7 @@ use try_fold::TryFoldFuture;
91
92
use try_for_each:: TryForEachFuture ;
92
93
93
94
pub use chain:: Chain ;
95
+ pub use cloned:: Cloned ;
94
96
pub use copied:: Copied ;
95
97
pub use filter:: Filter ;
96
98
pub use fuse:: Fuse ;
@@ -379,6 +381,40 @@ extension_trait! {
379
381
Chain :: new( self , other)
380
382
}
381
383
384
+ #[ doc = r#"
385
+ Creates an stream which copies all of its elements.
386
+
387
+ # Examples
388
+
389
+ Basic usage:
390
+
391
+ ```
392
+ # fn main() { async_std::task::block_on(async {
393
+ #
394
+ use async_std::prelude::*;
395
+ use async_std::stream;
396
+
397
+ let v = stream::from_iter(vec![&1, &2, &3]);
398
+
399
+ let mut v_cloned = v.cloned();
400
+
401
+ assert_eq!(v_cloned.next().await, Some(1));
402
+ assert_eq!(v_cloned.next().await, Some(2));
403
+ assert_eq!(v_cloned.next().await, Some(3));
404
+ assert_eq!(v_cloned.next().await, None);
405
+
406
+ #
407
+ # }) }
408
+ ```
409
+ "# ]
410
+ fn cloned<' a, T >( self ) -> Cloned <Self >
411
+ where
412
+ Self : Sized + Stream <Item = & ' a T >,
413
+ T : ' a + Clone ,
414
+ {
415
+ Cloned :: new( self )
416
+ }
417
+
382
418
383
419
#[ doc = r#"
384
420
Creates an stream which copies all of its elements.
@@ -394,8 +430,6 @@ extension_trait! {
394
430
use async_std::stream;
395
431
396
432
let s = stream::from_iter(vec![&1, &2, &3]);
397
- let second = stream::from_iter(vec![2, 3]);
398
-
399
433
let mut s_copied = s.copied();
400
434
401
435
assert_eq!(s_copied.next().await, Some(1));
0 commit comments