From e48e4637361c37cc18d447c5ec3fc2eb135c6fd5 Mon Sep 17 00:00:00 2001 From: razican Date: Mon, 11 Nov 2019 11:26:32 +0100 Subject: [PATCH] Duplicating code due to strange Rust error. --- src/stream/stream/merge.rs | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/stream/stream/merge.rs b/src/stream/stream/merge.rs index 6c8c20b7..b08b586e 100644 --- a/src/stream/stream/merge.rs +++ b/src/stream/stream/merge.rs @@ -45,26 +45,25 @@ where fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let this = self.project(); if utils::random(1) == 1 { - poll_next_in_order(cx, this.left, this.right) + match this.left.poll_next(cx) { + Poll::Ready(Some(item)) => Poll::Ready(Some(item)), + Poll::Ready(None) => this.right.poll_next(cx), + Poll::Pending => match this.right.poll_next(cx) { + Poll::Ready(Some(item)) => Poll::Ready(Some(item)), + Poll::Ready(None) => Poll::Pending, + Poll::Pending => Poll::Pending, + }, + } } else { - poll_next_in_order(cx, this.right, this.left) + match this.right.poll_next(cx) { + Poll::Ready(Some(item)) => Poll::Ready(Some(item)), + Poll::Ready(None) => this.left.poll_next(cx), + Poll::Pending => match this.left.poll_next(cx) { + Poll::Ready(Some(item)) => Poll::Ready(Some(item)), + Poll::Ready(None) => Poll::Pending, + Poll::Pending => Poll::Pending, + }, + } } } } - -/// Pools the next item, trying in order, first the first item, then the second one. -fn poll_next_in_order(cx: &mut Context<'_>, first: F, second: S) -> Poll> -where - F: Stream, - S: Stream, -{ - match first.poll_next(cx) { - Poll::Ready(Some(item)) => Poll::Ready(Some(item)), - Poll::Ready(None) => second.poll_next(cx), - Poll::Pending => match second.poll_next(cx) { - Poll::Ready(Some(item)) => Poll::Ready(Some(item)), - Poll::Ready(None) => Poll::Pending, - Poll::Pending => Poll::Pending, - }, - } -}