mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-07 00:00:09 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user