1 //! Asynchronous streams.
2 //!
3 //! This module contains:
4 //!
5 //! - The [`Stream`] trait, for objects that can asynchronously produce a
6 //!   sequence of values.
7 //! - The [`StreamExt`] and [`TryStreamExt`] trait, which provides adapters for
8 //!   chaining and composing streams.
9 //! - Top-level stream constructors like [`iter`](iter()) which creates a
10 //!   stream from an iterator.
11 
12 #[cfg(feature = "alloc")]
13 pub use futures_core::stream::{BoxStream, LocalBoxStream};
14 pub use futures_core::stream::{FusedStream, Stream, TryStream};
15 
16 // Extension traits and combinators
17 
18 #[allow(clippy::module_inception)]
19 mod stream;
20 pub use self::stream::{
21     Chain, Collect, Concat, Cycle, Enumerate, Filter, FilterMap, FlatMap, Flatten, Fold, ForEach,
22     Fuse, Inspect, Map, Next, NextIf, NextIfEq, Peek, Peekable, Scan, SelectNextSome, Skip,
23     SkipWhile, StreamExt, StreamFuture, Take, TakeUntil, TakeWhile, Then, Unzip, Zip,
24 };
25 
26 #[cfg(feature = "std")]
27 pub use self::stream::CatchUnwind;
28 
29 #[cfg(feature = "alloc")]
30 pub use self::stream::Chunks;
31 
32 #[cfg(feature = "alloc")]
33 pub use self::stream::ReadyChunks;
34 
35 #[cfg(feature = "sink")]
36 #[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
37 pub use self::stream::Forward;
38 
39 #[cfg(not(futures_no_atomic_cas))]
40 #[cfg(feature = "alloc")]
41 pub use self::stream::{BufferUnordered, Buffered, ForEachConcurrent};
42 
43 #[cfg(not(futures_no_atomic_cas))]
44 #[cfg(feature = "sink")]
45 #[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
46 #[cfg(feature = "alloc")]
47 pub use self::stream::{ReuniteError, SplitSink, SplitStream};
48 
49 mod try_stream;
50 pub use self::try_stream::{
51     try_unfold, AndThen, ErrInto, InspectErr, InspectOk, IntoStream, MapErr, MapOk, OrElse,
52     TryCollect, TryConcat, TryFilter, TryFilterMap, TryFlatten, TryFold, TryForEach, TryNext,
53     TrySkipWhile, TryStreamExt, TryTakeWhile, TryUnfold,
54 };
55 
56 #[cfg(feature = "io")]
57 #[cfg_attr(docsrs, doc(cfg(feature = "io")))]
58 #[cfg(feature = "std")]
59 pub use self::try_stream::IntoAsyncRead;
60 
61 #[cfg(not(futures_no_atomic_cas))]
62 #[cfg(feature = "alloc")]
63 pub use self::try_stream::{TryBufferUnordered, TryBuffered, TryForEachConcurrent};
64 
65 // Primitive streams
66 
67 mod iter;
68 pub use self::iter::{iter, Iter};
69 
70 mod repeat;
71 pub use self::repeat::{repeat, Repeat};
72 
73 mod repeat_with;
74 pub use self::repeat_with::{repeat_with, RepeatWith};
75 
76 mod empty;
77 pub use self::empty::{empty, Empty};
78 
79 mod once;
80 pub use self::once::{once, Once};
81 
82 mod pending;
83 pub use self::pending::{pending, Pending};
84 
85 mod poll_fn;
86 pub use self::poll_fn::{poll_fn, PollFn};
87 
88 mod select;
89 pub use self::select::{select, Select};
90 
91 mod unfold;
92 pub use self::unfold::{unfold, Unfold};
93 
94 cfg_target_has_atomic! {
95     #[cfg(feature = "alloc")]
96     mod futures_ordered;
97     #[cfg(feature = "alloc")]
98     pub use self::futures_ordered::FuturesOrdered;
99 
100     #[cfg(feature = "alloc")]
101     pub mod futures_unordered;
102     #[cfg(feature = "alloc")]
103     #[doc(inline)]
104     pub use self::futures_unordered::FuturesUnordered;
105 
106     #[cfg(feature = "alloc")]
107     pub mod select_all;
108     #[cfg(feature = "alloc")]
109     pub use self::select_all::{select_all, SelectAll};
110 
111     #[cfg(feature = "alloc")]
112     mod abortable;
113     #[cfg(feature = "alloc")]
114     pub use crate::abortable::{Abortable, AbortHandle, AbortRegistration, Aborted};
115     #[cfg(feature = "alloc")]
116     pub use abortable::abortable;
117 }
118 
119 // Just a helper function to ensure the streams we're returning all have the
120 // right implementations.
assert_stream<T, S>(stream: S) -> S where S: Stream<Item = T>,121 pub(crate) fn assert_stream<T, S>(stream: S) -> S
122 where
123     S: Stream<Item = T>,
124 {
125     stream
126 }
127