Skip to content

Commit c8f3539

Browse files
stream: make stream adapters public (#6658)
1 parent b2e4c5f commit c8f3539

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

tokio-stream/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,22 @@ pub mod wrappers;
8181

8282
mod stream_ext;
8383
pub use stream_ext::{collect::FromStream, StreamExt};
84+
/// Adapters for [`Stream`]s created by methods in [`StreamExt`].
85+
pub mod adapters {
86+
pub use crate::stream_ext::{
87+
Chain, Filter, FilterMap, Fuse, Map, MapWhile, Merge, Peekable, Skip, SkipWhile, Take,
88+
TakeWhile, Then,
89+
};
90+
cfg_time! {
91+
pub use crate::stream_ext::{ChunksTimeout, Timeout, TimeoutRepeating};
92+
}
93+
}
94+
8495
cfg_time! {
85-
pub use stream_ext::timeout::{Elapsed, Timeout};
96+
#[deprecated = "Import those symbols from adapters instead"]
97+
#[doc(hidden)]
98+
pub use stream_ext::timeout::Timeout;
99+
pub use stream_ext::timeout::Elapsed;
86100
}
87101

88102
mod empty;

tokio-stream/src/stream_ext.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,66 @@ mod any;
88
use any::AnyFuture;
99

1010
mod chain;
11-
use chain::Chain;
11+
pub use chain::Chain;
1212

1313
pub(crate) mod collect;
1414
use collect::{Collect, FromStream};
1515

1616
mod filter;
17-
use filter::Filter;
17+
pub use filter::Filter;
1818

1919
mod filter_map;
20-
use filter_map::FilterMap;
20+
pub use filter_map::FilterMap;
2121

2222
mod fold;
2323
use fold::FoldFuture;
2424

2525
mod fuse;
26-
use fuse::Fuse;
26+
pub use fuse::Fuse;
2727

2828
mod map;
29-
use map::Map;
29+
pub use map::Map;
3030

3131
mod map_while;
32-
use map_while::MapWhile;
32+
pub use map_while::MapWhile;
3333

3434
mod merge;
35-
use merge::Merge;
35+
pub use merge::Merge;
3636

3737
mod next;
3838
use next::Next;
3939

4040
mod skip;
41-
use skip::Skip;
41+
pub use skip::Skip;
4242

4343
mod skip_while;
44-
use skip_while::SkipWhile;
44+
pub use skip_while::SkipWhile;
4545

4646
mod take;
47-
use take::Take;
47+
pub use take::Take;
4848

4949
mod take_while;
50-
use take_while::TakeWhile;
50+
pub use take_while::TakeWhile;
5151

5252
mod then;
53-
use then::Then;
53+
pub use then::Then;
5454

5555
mod try_next;
5656
use try_next::TryNext;
5757

5858
mod peekable;
59-
use peekable::Peekable;
59+
pub use peekable::Peekable;
6060

6161
cfg_time! {
6262
pub(crate) mod timeout;
6363
pub(crate) mod timeout_repeating;
64-
use timeout::Timeout;
65-
use timeout_repeating::TimeoutRepeating;
64+
pub use timeout::Timeout;
65+
pub use timeout_repeating::TimeoutRepeating;
6666
use tokio::time::{Duration, Interval};
6767
mod throttle;
6868
use throttle::{throttle, Throttle};
6969
mod chunks_timeout;
70-
use chunks_timeout::ChunksTimeout;
70+
pub use chunks_timeout::ChunksTimeout;
7171
}
7272

7373
/// An extension trait for the [`Stream`] trait that provides a variety of

tokio-stream/tests/stream_chain.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ mod support {
66
}
77

88
use support::mpsc;
9+
use tokio_stream::adapters::Chain;
910

1011
#[tokio::test]
1112
async fn basic_usage() {
1213
let one = stream::iter(vec![1, 2, 3]);
1314
let two = stream::iter(vec![4, 5, 6]);
1415

15-
let mut stream = one.chain(two);
16+
let mut stream = visibility_test(one, two);
1617

1718
assert_eq!(stream.size_hint(), (6, Some(6)));
1819
assert_eq!(stream.next().await, Some(1));
@@ -39,6 +40,14 @@ async fn basic_usage() {
3940
assert_eq!(stream.next().await, None);
4041
}
4142

43+
fn visibility_test<I, S1, S2>(s1: S1, s2: S2) -> Chain<S1, S2>
44+
where
45+
S1: Stream<Item = I>,
46+
S2: Stream<Item = I>,
47+
{
48+
s1.chain(s2)
49+
}
50+
4251
#[tokio::test]
4352
async fn pending_first() {
4453
let (tx1, rx1) = mpsc::unbounded_channel_stream();

0 commit comments

Comments
 (0)