From 2323ac9a8eec2309073abc8861636351fbd7c28b Mon Sep 17 00:00:00 2001 From: Oleg Nosov Date: Fri, 12 Jun 2020 18:03:07 +0300 Subject: [PATCH] Apply suggestions from code review Co-authored-by: nasa --- src/stream/stream/flat_map.rs | 20 +++++++------------- src/stream/stream/flatten.rs | 18 ++++++------------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/stream/stream/flat_map.rs b/src/stream/stream/flat_map.rs index f9ceb86..97f5737 100644 --- a/src/stream/stream/flat_map.rs +++ b/src/stream/stream/flat_map.rs @@ -51,22 +51,16 @@ where let mut this = self.project(); loop { if let Some(inner) = this.inner_stream.as_mut().as_pin_mut() { - let next_item = futures_core::ready!(inner.poll_next(cx)); - - if next_item.is_some() { - return Poll::Ready(next_item); - } else { - this.inner_stream.set(None); + match futures_core::ready!(inner.poll_next(cx)) { + item @ Some(_) => return Poll::Ready(item), + None => this.inner_stream.set(None), } } - let inner = futures_core::ready!(this.stream.as_mut().poll_next(cx)); - - if inner.is_some() { - this.inner_stream.set(inner.map(IntoStream::into_stream)); - } else { - return Poll::Ready(None); + match futures_core::ready!(this.stream.as_mut().poll_next(cx)) { + inner @ Some(_) => this.inner_stream.set(inner.map(IntoStream::into_stream)), + None => return Poll::Ready(None), } } } -} \ No newline at end of file +} diff --git a/src/stream/stream/flatten.rs b/src/stream/stream/flatten.rs index 13975f7..5f8d000 100644 --- a/src/stream/stream/flatten.rs +++ b/src/stream/stream/flatten.rs @@ -52,21 +52,15 @@ where let mut this = self.project(); loop { if let Some(inner) = this.inner_stream.as_mut().as_pin_mut() { - let next_item = futures_core::ready!(inner.poll_next(cx)); - - if next_item.is_some() { - return Poll::Ready(next_item); - } else { - this.inner_stream.set(None); + match futures_core::ready!(inner.poll_next(cx)) { + item @ Some(_) => return Poll::Ready(next_item), + None => this.inner_stream.set(None), } } - let inner = futures_core::ready!(this.stream.as_mut().poll_next(cx)); - - if inner.is_some() { - this.inner_stream.set(inner.map(IntoStream::into_stream)); - } else { - return Poll::Ready(None); + match futures_core::ready!(this.stream.as_mut().poll_next(cx)) { + inner @ Some(_) => this.inner_stream.set(inner.map(IntoStream::into_stream)), + None => Poll::Ready(None), } } }