-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fs-stream-find-map
- Loading branch information
Showing
13 changed files
with
266 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::marker::PhantomData; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
/// A stream that both filters and maps. | ||
#[derive(Clone, Debug)] | ||
pub struct FilterMap<S, F, T, B> { | ||
stream: S, | ||
f: F, | ||
__from: PhantomData<T>, | ||
__to: PhantomData<B>, | ||
} | ||
|
||
impl<S, F, T, B> FilterMap<S, F, T, B> { | ||
pin_utils::unsafe_pinned!(stream: S); | ||
pin_utils::unsafe_unpinned!(f: F); | ||
|
||
pub(crate) fn new(stream: S, f: F) -> Self { | ||
FilterMap { | ||
stream, | ||
f, | ||
__from: PhantomData, | ||
__to: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<S, F, B> futures_core::stream::Stream for FilterMap<S, F, S::Item, B> | ||
where | ||
S: futures_core::stream::Stream, | ||
F: FnMut(S::Item) -> Option<B>, | ||
{ | ||
type Item = B; | ||
|
||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
let next = futures_core::ready!(self.as_mut().stream().poll_next(cx)); | ||
match next { | ||
Some(v) => match (self.as_mut().f())(v) { | ||
Some(b) => Poll::Ready(Some(b)), | ||
None => { | ||
cx.waker().wake_by_ref(); | ||
Poll::Pending | ||
} | ||
}, | ||
None => Poll::Ready(None), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.