futures_test/stream/mod.rs
1//! Additional combinators for testing streams.
2
3use futures_core::stream::Stream;
4
5pub use crate::interleave_pending::InterleavePending;
6
7/// Additional combinators for testing streams.
8pub trait StreamTestExt: Stream {
9 /// Introduces an extra [`Poll::Pending`](futures_core::task::Poll::Pending)
10 /// in between each item of the stream.
11 ///
12 /// # Examples
13 ///
14 /// ```
15 /// use futures::task::Poll;
16 /// use futures::stream::{self, Stream};
17 /// use futures_test::task::noop_context;
18 /// use futures_test::stream::StreamTestExt;
19 /// use futures::pin_mut;
20 ///
21 /// let stream = stream::iter(vec![1, 2]).interleave_pending();
22 /// pin_mut!(stream);
23 ///
24 /// let mut cx = noop_context();
25 ///
26 /// assert_eq!(stream.as_mut().poll_next(&mut cx), Poll::Pending);
27 /// assert_eq!(stream.as_mut().poll_next(&mut cx), Poll::Ready(Some(1)));
28 /// assert_eq!(stream.as_mut().poll_next(&mut cx), Poll::Pending);
29 /// assert_eq!(stream.as_mut().poll_next(&mut cx), Poll::Ready(Some(2)));
30 /// assert_eq!(stream.as_mut().poll_next(&mut cx), Poll::Pending);
31 /// assert_eq!(stream.as_mut().poll_next(&mut cx), Poll::Ready(None));
32 /// ```
33 fn interleave_pending(self) -> InterleavePending<Self>
34 where
35 Self: Sized,
36 {
37 InterleavePending::new(self)
38 }
39}
40
41impl<St> StreamTestExt for St where St: Stream {}