From 9c465e2f427f12999054bf086682080764dd3364 Mon Sep 17 00:00:00 2001 From: linkmauve Date: Fri, 10 Jul 2026 21:33:24 +0200 Subject: [PATCH] tokio-stream: Simplify TakeWhile with Option::filter() (#8268) Option::filter() exists since Rust 1.27.0, and is much more readable than the open coded variant that was there before, using Option::and_then(). This has been found by clippy. --- tokio-stream/src/stream_ext/take_while.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tokio-stream/src/stream_ext/take_while.rs b/tokio-stream/src/stream_ext/take_while.rs index eee104059..c228a292c 100644 --- a/tokio-stream/src/stream_ext/take_while.rs +++ b/tokio-stream/src/stream_ext/take_while.rs @@ -49,13 +49,7 @@ where fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { if !*self.as_mut().project().done { self.as_mut().project().stream.poll_next(cx).map(|ready| { - let ready = ready.and_then(|item| { - if !(self.as_mut().project().predicate)(&item) { - None - } else { - Some(item) - } - }); + let ready = ready.filter(self.as_mut().project().predicate); if ready.is_none() { *self.as_mut().project().done = true;