channel: Add try_recv and deprecate try_next #2944
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds
try_recv
and deprecatestry_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:
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 usingtry_next
just to make sure it isn't somehow broken.Adding
recv
aswell proved harder than expected because I can't add a dependency onfutures-util
, which would be cyclic. I see two options:futures-channel
specific code fromfutures-util
and move it intofutures-channel
.Next
asRecv
. Might be reasonable asNext
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