std::ops::Try impl for std::task::Poll#52721
Conversation
|
So that I understand these type signatures correctly, this is for converting |
|
@seanmonstar Right, this is just like if you were to use |
|
I like this factoring (of just handling the error conversions here, and leaving macros for readiness projection). And in any case, 👍 for trying it out and seeing how it feels! @bors r+ |
|
📌 Commit bce8a91 has been approved by |
|
🌲 The tree is currently closed for pull requests below priority 99, this pull request will be tested once the tree is reopened |
|
I think it's a good idea to try this out. However, it has to prove itself. In particular I would like to see some of our combinators converted to this new style. BTW where is the difference between: let x = ready!(future.poll()?);
let x = ready!(future.poll())?;I see that it's different for So, let's try it, but I remain skeptical |
|
Okay never mind. I understand the difference now: |
std::ops::Try impl for std::task::Poll I originally left out the `Try` impl for `Poll` because I was curious if we needed it, and @MajorBreakfast and I had discussed the potential for it to introduce confusion about exactly what control-flow was happening at different points. However, after porting a pretty significant chunk of Fuchsia over to futures 0.3, I discovered that I was *constantly* having to do repetitive matching on `Poll<Result<...>>` or `Poll<Option<Result<...>>>` in order to propagate errors correctly. `try_poll` (propagate `Poll::Ready(Err(..))`s) helped in some places, but it was far more common to need some form of conversion between `Result`, `Poll<Result<...>>`, and `Poll<Option<Result<...>>>`. The `Try` trait conveniently provides all of these conversions in addition to a more concise syntax (`?`), so I'd like to experiment with using these instead. cc @seanmonstar r? @aturon Note: this change means that far more futures 0.1 code can work without significant changes since it papers over the fact that `Result` is no longer at the top-level when using `Stream` and `Future` (since it's now `Poll<Result<...>>` or `Poll<Option<Result<...>>>` instead of `Result<Poll<..>>` and `Result<Poll<Option<...>>>`).
The first one will first check for errors, return them if necessary, then check for |
|
@cramertj No I was wrong there. The second one won't actually work because |
When using |
Rollup of 16 pull requests Successful merges: - #52558 (Add tests for ICEs which no longer repro) - #52610 (Clarify what a task is) - #52617 (Don't match on region kinds when reporting NLL errors) - #52635 (Fix #[linkage] propagation though generic functions) - #52647 (Suggest to take and ignore args while closure args count mismatching) - #52649 (Point spans to inner elements of format strings) - #52654 (Format linker args in a way that works for gcc and ld) - #52667 (update the stdsimd submodule) - #52674 (Impl Executor for Box<E: Executor>) - #52690 (ARM: expose `rclass` and `dsp` target features) - #52692 (Improve readability in a few sorts) - #52695 (Hide some lints which are not quite right the way they are reported to the user) - #52718 (State default capacity for BufReader/BufWriter) - #52721 (std::ops::Try impl for std::task::Poll) - #52723 (rustc: Register crates under their real names) - #52734 (sparc ABI issue - structure returning from function is returned in 64bit registers (with tests)) Failed merges: - #52678 ([NLL] Use better spans in some errors) r? @ghost
|
@cramertj Ah I see. It seems that |
I originally left out the
Tryimpl forPollbecause I was curious if we needed it, and @MajorBreakfast and I had discussed the potential for it to introduce confusion about exactly what control-flow was happening at different points. However, after porting a pretty significant chunk of Fuchsia over to futures 0.3, I discovered that I was constantly having to do repetitive matching onPoll<Result<...>>orPoll<Option<Result<...>>>in order to propagate errors correctly.try_poll(propagatePoll::Ready(Err(..))s) helped in some places, but it was far more common to need some form of conversion betweenResult,Poll<Result<...>>, andPoll<Option<Result<...>>>. TheTrytrait conveniently provides all of these conversions in addition to a more concise syntax (?), so I'd like to experiment with using these instead.cc @seanmonstar
r? @aturon
Note: this change means that far more futures 0.1 code can work without significant changes since it papers over the fact that
Resultis no longer at the top-level when usingStreamandFuture(since it's nowPoll<Result<...>>orPoll<Option<Result<...>>>instead ofResult<Poll<..>>andResult<Poll<Option<...>>>).