-
Notifications
You must be signed in to change notification settings - Fork 341
Adds Stream::cmp #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Stream::cmp #273
Conversation
cc/ @montekki can I ask you to review this? 😊 |
@assemblaj @yoshuawuyts generally LGTM, but it would be super great to explore in the future some single generic version of these comparison combinators and implement them all with it. Does the regular std do something of this kind? Probably we need to take a look. |
@montekki For the most part std just uses duplicate code for all of the comparison functions, I think. But those implementations are more simple in nature. |
it looks like |
partial_cmp_by and cmp_by seem to be helper functions that are only used by partial_cmp and cmp, respectively. The rest of the comparison functions (lt, gt, ne, etc) are built with partial_cmp, cmp, and eq though. Using that approach seems like a good idea, if feasible. What's the syntax for using a Future within another Future? Would you just use '.await'? |
other: S | ||
) -> impl Future<Output = Ordering> [CmpFuture<Self, S>] | ||
where | ||
Self: Sized + Stream, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Self: Stream
necessary at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I remove + Stream
from this clause , it builds and passes tests but I get the following error from rustdoc:
error[E0277]: the trait bound `Self: stream::stream::Stream` is not satisfied
--> src/stream/stream/mod.rs:1180:9
|
1180 | / fn cmp<S>(
1181 | | self,
1182 | | other: S
1183 | | ) -> impl Future<Output = Ordering> [CmpFuture<Self, S>]
... |
1189 | | CmpFuture::new(self, other)
1190 | | }
| |_________^ the trait `stream::stream::Stream` is not implemented for `Self`
|
= help: consider adding a `where Self: stream::stream::Stream` bound
self, | ||
other: S | ||
) -> impl Future<Output = Ordering> [CmpFuture<Self, S>] | ||
where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we missing Self::Item: Ord
here? I see Iterator::cmp
has this bound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct, I'd erroneously removed this to pass rustdoc tests. Pushing a commit to fix this.
88ad6fe
to
cc049a0
Compare
Very similar to partial_cmp, primary difference is that cmp is used for the comparison instead of partial_cmp and as such the code was changed to accommodate that (Item's implement Ord instead of PartialOrd, Ordering is returned instead of Option), etc