Skip to content
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

channel: Add try_recv and deprecate try_next #2944

Merged
merged 2 commits into from
Apr 9, 2025

Conversation

cmrschwarz
Copy link
Contributor

@cmrschwarz cmrschwarz commented Apr 7, 2025

Adds try_recv and deprecates try_next as discussed in #2936.

It does so by changing the previously private TryRecvError internals from a struct to an an enum.

Note that this is technically not semver compatible with 0.3 as the following is legal (albeit nonsensical) Rust:

let TryRecvError {..} = my_err;

This would no longer compile after this change.
I'm happy to introduce some slightly hacky TryReceiveError or similar instead if that is preferred.


I've also moved most most tests over to try_recv but kept around these two using try_next just to make sure it isn't somehow broken.


Adding recv aswell proved harder than expected because I can't add a dependency on
futures-util, which would be cyclic. I see two options:

  1. Take out the futures-channel specific code from futures-util and move it into futures-channel.
  2. Essentially reimplement Next as Recv. Might be reasonable as Next is pretty small.

Which would you prefer? I'm happy do do either as a follow up if that still seems good, or of course do a third option if there's a better Idea.


Closes #2936
Closes #2197

@rustbot rustbot added A-channel Area: futures::channel S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 7, 2025
@cmrschwarz
Copy link
Contributor Author

Sorry for the double CI, I accidentally left a comment that doesn't make sense anymore. Fixed.

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

As for recv, I think it is reasonable to copy the code of Next from futures-util. It is small enough.

@taiki-e taiki-e changed the title Try recv channel: Add try_recv and deprecate try_next Apr 9, 2025
@taiki-e taiki-e merged commit 89e5d8b into rust-lang:master Apr 9, 2025
24 checks passed
@taiki-e taiki-e added 0.3-backport: pending The maintainer accepted to backport this to the 0.3 branch, but backport has not been done yet. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.3-backport: pending The maintainer accepted to backport this to the 0.3 branch, but backport has not been done yet. A-channel Area: futures::channel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

api: consider changing mpsc::Receiver::try_next for future_channels v0.4. rename mpsc::Receiver::try_next
3 participants