• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     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")]
28 pub use self::stream::CatchUnwind;
29 
30 #[cfg(feature = "alloc")]
31 pub use self::stream::Chunks;
32 
33 #[cfg(feature = "alloc")]
34 pub use self::stream::ReadyChunks;
35 
36 #[cfg(feature = "sink")]
37 #[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
38 pub use self::stream::Forward;
39 
40 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
41 #[cfg(feature = "alloc")]
42 pub use self::stream::{
43     BufferUnordered, Buffered, FlatMapUnordered, FlattenUnordered, ForEachConcurrent,
44 };
45 
46 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
47 #[cfg(feature = "sink")]
48 #[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
49 #[cfg(feature = "alloc")]
50 pub use self::stream::{ReuniteError, SplitSink, SplitStream};
51 
52 mod try_stream;
53 pub use self::try_stream::{
54     try_unfold, AndThen, ErrInto, InspectErr, InspectOk, IntoStream, MapErr, MapOk, OrElse, TryAll,
55     TryAny, TryCollect, TryConcat, TryFilter, TryFilterMap, TryFlatten, TryFold, TryForEach,
56     TryNext, TrySkipWhile, TryStreamExt, TryTakeWhile, TryUnfold,
57 };
58 
59 #[cfg(feature = "io")]
60 #[cfg_attr(docsrs, doc(cfg(feature = "io")))]
61 #[cfg(feature = "std")]
62 pub use self::try_stream::IntoAsyncRead;
63 
64 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
65 #[cfg(feature = "alloc")]
66 pub use self::try_stream::{
67     TryBufferUnordered, TryBuffered, TryFlattenUnordered, TryForEachConcurrent,
68 };
69 
70 #[cfg(feature = "alloc")]
71 pub use self::try_stream::{TryChunks, TryChunksError, TryReadyChunks, TryReadyChunksError};
72 
73 // Primitive streams
74 
75 mod iter;
76 pub use self::iter::{iter, Iter};
77 
78 mod repeat;
79 pub use self::repeat::{repeat, Repeat};
80 
81 mod repeat_with;
82 pub use self::repeat_with::{repeat_with, RepeatWith};
83 
84 mod empty;
85 pub use self::empty::{empty, Empty};
86 
87 mod once;
88 pub use self::once::{once, Once};
89 
90 mod pending;
91 pub use self::pending::{pending, Pending};
92 
93 mod poll_fn;
94 pub use self::poll_fn::{poll_fn, PollFn};
95 
96 mod poll_immediate;
97 pub use self::poll_immediate::{poll_immediate, PollImmediate};
98 
99 mod select;
100 pub use self::select::{select, Select};
101 
102 mod select_with_strategy;
103 pub use self::select_with_strategy::{select_with_strategy, PollNext, SelectWithStrategy};
104 
105 mod unfold;
106 pub use self::unfold::{unfold, Unfold};
107 
108 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
109 #[cfg(feature = "alloc")]
110 mod futures_ordered;
111 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
112 #[cfg(feature = "alloc")]
113 pub use self::futures_ordered::FuturesOrdered;
114 
115 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
116 #[cfg(feature = "alloc")]
117 pub mod futures_unordered;
118 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
119 #[cfg(feature = "alloc")]
120 #[doc(inline)]
121 pub use self::futures_unordered::FuturesUnordered;
122 
123 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
124 #[cfg(feature = "alloc")]
125 pub mod select_all;
126 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
127 #[cfg(feature = "alloc")]
128 #[doc(inline)]
129 pub use self::select_all::{select_all, SelectAll};
130 
131 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
132 #[cfg(feature = "alloc")]
133 mod abortable;
134 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
135 #[cfg(feature = "alloc")]
136 pub use crate::abortable::{AbortHandle, AbortRegistration, Abortable, Aborted};
137 #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
138 #[cfg(feature = "alloc")]
139 pub use abortable::abortable;
140 
141 // Just a helper function to ensure the streams we're returning all have the
142 // right implementations.
assert_stream<T, S>(stream: S) -> S where S: Stream<Item = T>,143 pub(crate) fn assert_stream<T, S>(stream: S) -> S
144 where
145     S: Stream<Item = T>,
146 {
147     stream
148 }
149