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")]
13pub use futures_core::stream::{BoxStream, LocalBoxStream};
14pub use futures_core::stream::{FusedStream, Stream, TryStream};
15
16// Extension traits and combinators
17
18#[allow(clippy::module_inception)]
19mod stream;
20pub use self::stream::{
21 All, Any, Chain, Collect, Concat, Count, Cycle, Enumerate, Filter, FilterMap, FlatMap, Flatten,
22 Fold, ForEach, Fuse, Inspect, Map, Next, NextIf, NextIfEq, Peek, PeekMut, Peekable, Scan,
23 SelectNextSome, Skip, SkipWhile, StreamExt, StreamFuture, Take, TakeUntil, TakeWhile, Then,
24 Unzip, Zip,
25};
26
27#[cfg(feature = "std")]
28pub use self::stream::CatchUnwind;
29
30#[cfg(feature = "alloc")]
31pub use self::stream::Chunks;
32
33#[cfg(feature = "alloc")]
34pub use self::stream::ReadyChunks;
35
36#[cfg(feature = "sink")]
37#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
38pub use self::stream::Forward;
39
40#[cfg(not(futures_no_atomic_cas))]
41#[cfg(feature = "alloc")]
42pub use self::stream::{
43 BufferUnordered, Buffered, FlatMapUnordered, FlattenUnordered, ForEachConcurrent,
44};
45
46#[cfg(not(futures_no_atomic_cas))]
47#[cfg(feature = "sink")]
48#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
49#[cfg(feature = "alloc")]
50pub use self::stream::{ReuniteError, SplitSink, SplitStream};
51
52mod try_stream;
53pub use self::try_stream::{
54 try_unfold, AndThen, ErrInto, InspectErr, InspectOk, IntoStream, MapErr, MapOk, OrElse,
55 TryCollect, TryConcat, TryFilter, TryFilterMap, TryFlatten, TryFold, TryForEach, TryNext,
56 TrySkipWhile, TryStreamExt, TryTakeWhile, TryUnfold,
57};
58
59#[cfg(feature = "io")]
60#[cfg_attr(docsrs, doc(cfg(feature = "io")))]
61#[cfg(feature = "std")]
62pub use self::try_stream::IntoAsyncRead;
63
64#[cfg(not(futures_no_atomic_cas))]
65#[cfg(feature = "alloc")]
66pub use self::try_stream::{
67 TryBufferUnordered, TryBuffered, TryFlattenUnordered, TryForEachConcurrent,
68};
69
70#[cfg(feature = "alloc")]
71pub use self::try_stream::{TryChunks, TryChunksError};
72
73// Primitive streams
74
75mod iter;
76pub use self::iter::{iter, Iter};
77
78mod repeat;
79pub use self::repeat::{repeat, Repeat};
80
81mod repeat_with;
82pub use self::repeat_with::{repeat_with, RepeatWith};
83
84mod empty;
85pub use self::empty::{empty, Empty};
86
87mod once;
88pub use self::once::{once, Once};
89
90mod pending;
91pub use self::pending::{pending, Pending};
92
93mod poll_fn;
94pub use self::poll_fn::{poll_fn, PollFn};
95
96mod poll_immediate;
97pub use self::poll_immediate::{poll_immediate, PollImmediate};
98
99mod select;
100pub use self::select::{select, Select};
101
102mod select_with_strategy;
103pub use self::select_with_strategy::{select_with_strategy, PollNext, SelectWithStrategy};
104
105mod unfold;
106pub use self::unfold::{unfold, Unfold};
107
108#[cfg(not(futures_no_atomic_cas))]
109#[cfg(feature = "alloc")]
110mod futures_ordered;
111#[cfg(not(futures_no_atomic_cas))]
112#[cfg(feature = "alloc")]
113pub use self::futures_ordered::FuturesOrdered;
114
115#[cfg(not(futures_no_atomic_cas))]
116#[cfg(feature = "alloc")]
117pub mod futures_unordered;
118#[cfg(not(futures_no_atomic_cas))]
119#[cfg(feature = "alloc")]
120#[doc(inline)]
121pub use self::futures_unordered::FuturesUnordered;
122
123#[cfg(not(futures_no_atomic_cas))]
124#[cfg(feature = "alloc")]
125pub mod select_all;
126#[cfg(not(futures_no_atomic_cas))]
127#[cfg(feature = "alloc")]
128#[doc(inline)]
129pub use self::select_all::{select_all, SelectAll};
130
131#[cfg(not(futures_no_atomic_cas))]
132#[cfg(feature = "alloc")]
133mod abortable;
134#[cfg(not(futures_no_atomic_cas))]
135#[cfg(feature = "alloc")]
136pub use crate::abortable::{AbortHandle, AbortRegistration, Abortable, Aborted};
137#[cfg(not(futures_no_atomic_cas))]
138#[cfg(feature = "alloc")]
139pub use abortable::abortable;
140
141// Just a helper function to ensure the streams we're returning all have the
142// right implementations.
143pub(crate) fn assert_stream<T, S>(stream: S) -> S
144where
145 S: Stream<Item = T>,
146{
147 stream
148}
149