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, PeekMut, Peekable, Scan, SelectNextSome,
23 Skip, 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 #[cfg(feature = "alloc")]
66 pub use self::try_stream::{TryChunks, TryChunksError};
67
68 // Primitive streams
69
70 mod iter;
71 pub use self::iter::{iter, Iter};
72
73 mod repeat;
74 pub use self::repeat::{repeat, Repeat};
75
76 mod repeat_with;
77 pub use self::repeat_with::{repeat_with, RepeatWith};
78
79 mod empty;
80 pub use self::empty::{empty, Empty};
81
82 mod once;
83 pub use self::once::{once, Once};
84
85 mod pending;
86 pub use self::pending::{pending, Pending};
87
88 mod poll_fn;
89 pub use self::poll_fn::{poll_fn, PollFn};
90
91 mod poll_immediate;
92 pub use self::poll_immediate::{poll_immediate, PollImmediate};
93
94 mod select;
95 pub use self::select::{select, Select};
96
97 mod select_with_strategy;
98 pub use self::select_with_strategy::{select_with_strategy, PollNext, SelectWithStrategy};
99
100 mod unfold;
101 pub use self::unfold::{unfold, Unfold};
102
103 #[cfg(not(futures_no_atomic_cas))]
104 #[cfg(feature = "alloc")]
105 mod futures_ordered;
106 #[cfg(not(futures_no_atomic_cas))]
107 #[cfg(feature = "alloc")]
108 pub use self::futures_ordered::FuturesOrdered;
109
110 #[cfg(not(futures_no_atomic_cas))]
111 #[cfg(feature = "alloc")]
112 pub mod futures_unordered;
113 #[cfg(not(futures_no_atomic_cas))]
114 #[cfg(feature = "alloc")]
115 #[doc(inline)]
116 pub use self::futures_unordered::FuturesUnordered;
117
118 #[cfg(not(futures_no_atomic_cas))]
119 #[cfg(feature = "alloc")]
120 pub mod select_all;
121 #[cfg(not(futures_no_atomic_cas))]
122 #[cfg(feature = "alloc")]
123 #[doc(inline)]
124 pub use self::select_all::{select_all, SelectAll};
125
126 #[cfg(not(futures_no_atomic_cas))]
127 #[cfg(feature = "alloc")]
128 mod abortable;
129 #[cfg(not(futures_no_atomic_cas))]
130 #[cfg(feature = "alloc")]
131 pub use crate::abortable::{AbortHandle, AbortRegistration, Abortable, Aborted};
132 #[cfg(not(futures_no_atomic_cas))]
133 #[cfg(feature = "alloc")]
134 pub use abortable::abortable;
135
136 // Just a helper function to ensure the streams we're returning all have the
137 // right implementations.
assert_stream<T, S>(stream: S) -> S where S: Stream<Item = T>,138 pub(crate) fn assert_stream<T, S>(stream: S) -> S
139 where
140 S: Stream<Item = T>,
141 {
142 stream
143 }
144