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.
This commit is contained in:
linkmauve
2026-07-10 21:33:24 +02:00
committed by GitHub
parent d5950a8890
commit 9c465e2f42
+1 -7
View File
@@ -49,13 +49,7 @@ where
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
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;