| 1 | use core::cmp::Ordering; |
| 2 | use core::future::Future; |
| 3 | use core::pin::Pin; |
| 4 | |
| 5 | use pin_project_lite::pin_project; |
| 6 | |
| 7 | use super::partial_cmp::PartialCmpFuture; |
| 8 | use crate::stream::stream::StreamExt; |
| 9 | use crate::stream::Stream; |
| 10 | use crate::task::{Context, Poll}; |
| 11 | |
| 12 | pin_project! { |
| 13 | // Determines if the elements of this `Stream` are lexicographically |
| 14 | // greater than those of another. |
| 15 | #[doc (hidden)] |
| 16 | #[allow (missing_debug_implementations)] |
| 17 | pub struct GtFuture<L: Stream, R: Stream> { |
| 18 | #[pin] |
| 19 | partial_cmp: PartialCmpFuture<L, R>, |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | impl<L: Stream, R: Stream> GtFuture<L, R> |
| 24 | where |
| 25 | L::Item: PartialOrd<R::Item>, |
| 26 | { |
| 27 | pub(super) fn new(l: L, r: R) -> Self { |
| 28 | Self { |
| 29 | partial_cmp: l.partial_cmp(r), |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl<L: Stream, R: Stream> Future for GtFuture<L, R> |
| 35 | where |
| 36 | L: Stream + Sized, |
| 37 | R: Stream + Sized, |
| 38 | L::Item: PartialOrd<R::Item>, |
| 39 | { |
| 40 | type Output = bool; |
| 41 | |
| 42 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
| 43 | let result: Option = futures_core::ready!(self.project().partial_cmp.poll(cx)); |
| 44 | |
| 45 | match result { |
| 46 | Some(Ordering::Greater) => Poll::Ready(true), |
| 47 | _ => Poll::Ready(false), |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |