1use core::cmp::Ordering;
2use core::future::Future;
3use core::pin::Pin;
4
5use pin_project_lite::pin_project;
6
7use super::partial_cmp::PartialCmpFuture;
8use crate::stream::stream::StreamExt;
9use crate::stream::Stream;
10use crate::task::{Context, Poll};
11
12pin_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
23impl<L: Stream, R: Stream> GtFuture<L, R>
24where
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
34impl<L: Stream, R: Stream> Future for GtFuture<L, R>
35where
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