mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
tokio-stream: implement FusedStream for various stream adaptors (#8096)
`MapWhile` is intentionally excluded because its current implementation does not track when the closure returns `None` early, making a correct `is_terminated()` impossible without a separate semantic change.
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::Stream;
|
||||
use core::fmt;
|
||||
use core::pin::Pin;
|
||||
use core::task::{Context, Poll};
|
||||
use futures_core::FusedStream;
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
@@ -77,3 +78,13 @@ where
|
||||
(0, upper)
|
||||
}
|
||||
}
|
||||
|
||||
impl<St, F> FusedStream for TakeWhile<St, F>
|
||||
where
|
||||
St: Stream,
|
||||
F: FnMut(&St::Item) -> bool,
|
||||
{
|
||||
fn is_terminated(&self) -> bool {
|
||||
self.done
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user