-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feature: add support for StreamMap
to return on closed streams
#4851
Conversation
Adding a third generic parameter for this seems a bit overkill. I would definitely prefer just providing a wrapper stream for this use-case instead. |
@Darksonn I understand what you're saying, but it feels funny as of right now |
Whether or not the current design was a mistake doesn't really matter when it comes to designing how to add this feature. We need to pick the best design among the backwards compatible ones, and I don't agree that adding a third generic parameter is the best choice. |
What about changing the implementation based on a feature flag? |
Enabling a feature flag must never change the behavior of code that compiles without it. This is because the crate is only compiled once, so if multiple things depend on tokio-stream and only some of them enable the feature flag, then they all get the feature flag. |
Since changes to this PR have been requested, I am marking the PR as a draft. Please remove the draft marker when you would like me to review the PR again. If you no longer want to work on this PR, then please close the PR. |
Sorry, I hoped someone would have a better solution then the ones suggested so far. I'll change this PR to match your suggestion. |
Rewrote this as suggested (wrapper struct). |
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.
There are some minor issues that I have outlined below, but overall this looks really good! I'm happy to see that you included a test. :)
pin_project! { | ||
/// Stream that returns None when the stream is exhausted. To be used with StreamMap to know when a stream ends. | ||
#[must_use = "streams do nothing unless polled"] | ||
pub struct StreamNotifyClose<S> { |
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.
The name is not great — notify normally means something different. But I can't think of anything better.
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.
Totally agree. StreamClose
implies nothing really.. would love suggestions.
Thanks! Untested code is evil code ;) |
2515d3a
to
7168215
Compare
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.
I have some comments on your documentation.
There are some compilation failures in your documentation tests. You can see these on your local machine by running |
Thanks for the feedback. I have submitted changes according to it. |
…urns None when it ends, for use with StreamMap
Co-authored-by: Alice Ryhl <[email protected]>
You will need to run rustfmt to make CI happy. Other than that, my only concern about this is the naming. I still don't like using the word "notify" in the name for this. |
I'm running |
The |
|
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.
Hi. I'm sorry that this got lost. However, it LGTM, so I'll go ahead and merge it. Thank you for the PR.
Following #4847 - I think this is the best solution - I'm open to alternatives (especially as I'm not so good at generics, so there are probably improvements!)
Options I ruled out:
next_or_none
- would require many abstractions to be added (next
is only provided byStreamExt
that relies on other functions,poll
etc