1 use crate::stream::{Fuse, Stream}; 2 3 use core::pin::Pin; 4 use core::task::{Context, Poll}; 5 use pin_project_lite::pin_project; 6 7 pin_project! { 8 /// Stream returned by the [`chain`](super::StreamExt::chain) method. 9 pub struct Chain<T, U> { 10 #[pin] 11 a: Fuse<T>, 12 #[pin] 13 b: U, 14 } 15 } 16 17 impl<T, U> Chain<T, U> { new(a: T, b: U) -> Chain<T, U> where T: Stream, U: Stream,18 pub(super) fn new(a: T, b: U) -> Chain<T, U> 19 where 20 T: Stream, 21 U: Stream, 22 { 23 Chain { a: Fuse::new(a), b } 24 } 25 } 26 27 impl<T, U> Stream for Chain<T, U> 28 where 29 T: Stream, 30 U: Stream<Item = T::Item>, 31 { 32 type Item = T::Item; 33 poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T::Item>>34 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T::Item>> { 35 use Poll::Ready; 36 37 let me = self.project(); 38 39 if let Some(v) = ready!(me.a.poll_next(cx)) { 40 return Ready(Some(v)); 41 } 42 43 me.b.poll_next(cx) 44 } 45 size_hint(&self) -> (usize, Option<usize>)46 fn size_hint(&self) -> (usize, Option<usize>) { 47 super::merge_size_hints(self.a.size_hint(), self.b.size_hint()) 48 } 49 } 50