From 47ff9ad2317d2db202232327832940d86b720064 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 20 Aug 2024 22:32:12 +0900 Subject: [PATCH] copies: break method chaining in CopiesTreeDiffStream::poll_next() So that it can be wrapped within a while loop + continue. --- lib/src/copies.rs | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/src/copies.rs b/lib/src/copies.rs index 6b3da3c6c..404d477a2 100644 --- a/lib/src/copies.rs +++ b/lib/src/copies.rs @@ -16,7 +16,7 @@ use std::collections::HashMap; use std::pin::Pin; -use std::task::{Context, Poll}; +use std::task::{ready, Context, Poll}; use futures::Stream; @@ -121,28 +121,26 @@ impl Stream for CopiesTreeDiffStream<'_> { type Item = CopiesTreeDiffEntry; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.inner.as_mut().poll_next(cx).map(|option| { - option.map(|diff_entry| { - let Some(CopyRecord { source, .. }) = - self.copy_records.for_target(&diff_entry.path) - else { - return CopiesTreeDiffEntry { - source: diff_entry.path.clone(), - target: diff_entry.path, - value: diff_entry.value, - }; - }; + let Some(diff_entry) = ready!(self.inner.as_mut().poll_next(cx)) else { + return Poll::Ready(None); + }; - CopiesTreeDiffEntry { - source: source.clone(), - target: diff_entry.path, - value: diff_entry.value.and_then(|(_, target_value)| { - self.source_tree - .path_value(source) - .map(|source_value| (source_value, target_value)) - }), - } - }) - }) + let Some(CopyRecord { source, .. }) = self.copy_records.for_target(&diff_entry.path) else { + return Poll::Ready(Some(CopiesTreeDiffEntry { + source: diff_entry.path.clone(), + target: diff_entry.path, + value: diff_entry.value, + })); + }; + + Poll::Ready(Some(CopiesTreeDiffEntry { + source: source.clone(), + target: diff_entry.path, + value: diff_entry.value.and_then(|(_, target_value)| { + self.source_tree + .path_value(source) + .map(|source_value| (source_value, target_value)) + }), + })) } }