-
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.
149: update deps r=stjepang a=yoshuawuyts Updates all deps. Thanks! 150: split stream into multiple files r=stjepang a=yoshuawuyts This splits `stream/mod.rs`'s combinators into multiple files, making it easier to contribute combinators. Additionally we've renamed `MinBy` to `MinByFuture` to make it the same as the other private futures. Ref #146 #129. Thanks! Co-authored-by: Yoshua Wuyts <[email protected]> Co-authored-by: Stjepan Glavina <[email protected]>
- Loading branch information
Showing
8 changed files
with
181 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::future::Future; | ||
use crate::task::{Context, Poll}; | ||
|
||
use std::marker::PhantomData; | ||
use std::pin::Pin; | ||
|
||
#[derive(Debug)] | ||
pub struct AllFuture<'a, S, F, T> | ||
where | ||
F: FnMut(T) -> bool, | ||
{ | ||
pub(crate) stream: &'a mut S, | ||
pub(crate) f: F, | ||
pub(crate) result: bool, | ||
pub(crate) __item: PhantomData<T>, | ||
} | ||
|
||
impl<'a, S, F, T> AllFuture<'a, S, F, T> | ||
where | ||
F: FnMut(T) -> bool, | ||
{ | ||
pin_utils::unsafe_pinned!(stream: &'a mut S); | ||
pin_utils::unsafe_unpinned!(result: bool); | ||
pin_utils::unsafe_unpinned!(f: F); | ||
} | ||
|
||
impl<S, F> Future for AllFuture<'_, S, F, S::Item> | ||
where | ||
S: futures_core::stream::Stream + Unpin + Sized, | ||
F: FnMut(S::Item) -> bool, | ||
{ | ||
type Output = bool; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
use futures_core::stream::Stream; | ||
let next = futures_core::ready!(self.as_mut().stream().poll_next(cx)); | ||
match next { | ||
Some(v) => { | ||
let result = (self.as_mut().f())(v); | ||
*self.as_mut().result() = result; | ||
if result { | ||
// don't forget to wake this task again to pull the next item from stream | ||
cx.waker().wake_by_ref(); | ||
Poll::Pending | ||
} else { | ||
Poll::Ready(false) | ||
} | ||
} | ||
None => Poll::Ready(self.result), | ||
} | ||
} | ||
} |
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,52 @@ | ||
use crate::future::Future; | ||
use crate::task::{Context, Poll}; | ||
|
||
use std::marker::PhantomData; | ||
use std::pin::Pin; | ||
|
||
#[derive(Debug)] | ||
pub struct AnyFuture<'a, S, F, T> | ||
where | ||
F: FnMut(T) -> bool, | ||
{ | ||
pub(crate) stream: &'a mut S, | ||
pub(crate) f: F, | ||
pub(crate) result: bool, | ||
pub(crate) __item: PhantomData<T>, | ||
} | ||
|
||
impl<'a, S, F, T> AnyFuture<'a, S, F, T> | ||
where | ||
F: FnMut(T) -> bool, | ||
{ | ||
pin_utils::unsafe_pinned!(stream: &'a mut S); | ||
pin_utils::unsafe_unpinned!(result: bool); | ||
pin_utils::unsafe_unpinned!(f: F); | ||
} | ||
|
||
impl<S, F> Future for AnyFuture<'_, S, F, S::Item> | ||
where | ||
S: futures_core::stream::Stream + Unpin + Sized, | ||
F: FnMut(S::Item) -> bool, | ||
{ | ||
type Output = bool; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
use futures_core::stream::Stream; | ||
let next = futures_core::ready!(self.as_mut().stream().poll_next(cx)); | ||
match next { | ||
Some(v) => { | ||
let result = (self.as_mut().f())(v); | ||
*self.as_mut().result() = result; | ||
if result { | ||
Poll::Ready(true) | ||
} else { | ||
// don't forget to wake this task again to pull the next item from stream | ||
cx.waker().wake_by_ref(); | ||
Poll::Pending | ||
} | ||
} | ||
None => Poll::Ready(self.result), | ||
} | ||
} | ||
} |
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,17 @@ | ||
use crate::future::Future; | ||
use crate::task::{Context, Poll}; | ||
use std::pin::Pin; | ||
|
||
#[doc(hidden)] | ||
#[allow(missing_debug_implementations)] | ||
pub struct NextFuture<'a, T: Unpin + ?Sized> { | ||
pub(crate) stream: &'a mut T, | ||
} | ||
|
||
impl<T: futures_core::stream::Stream + Unpin + ?Sized> Future for NextFuture<'_, T> { | ||
type Output = Option<T::Item>; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
Pin::new(&mut *self.stream).poll_next(cx) | ||
} | ||
} |
Oops, something went wrong.