Uh oh!
There was an error while loading. Please reload this page.
Impl Try for Option - #42526
Conversation
rust-highfive
commented
Jun 8, 2017
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Yes, I needed something there in order to compile and forgot to change it. I'm not sure what to replace it with; maybe The equivalent of Option::None for a Result type.?
scottmcm
commented
Jun 8, 2017
This is exciting, and applying right after branching for release is probably the best option we have for insta-stable things like this. (This will allow Something I didn't want to push in the RFC discussion, but thought interesting: what about a That's intentionally non-constructible for now, since what I think it ought to be is Though I guess the type will stay unstable for a while, so it doesn't matter for now... |
There was a problem hiding this comment.
This is not going through the Option. I already works now... Maybe you meant to use Some here?
There was a problem hiding this comment.
This is also nothing new... maybe change it into a compile-fail test by using Some/None and triggering a compilation error
There was a problem hiding this comment.
I didn't see any tests for Result's Try implemenation, but if they exist I can remove these tests.
alexcrichton
commented
Jun 8, 2017
nikomatsakis
commented
Jun 9, 2017
I think one way to prevent it from being insta-stable would be to make it I am open to bikeshedding the name of |
MoSal
commented
Jun 10, 2017
Maybe |
kennytm
commented
Jun 10, 2017
nikomatsakis
commented
Jun 13, 2017
@kennytm well that was more about a public "cfg", but yeah apparently we don't have |
huntiep
commented
Jun 13, 2017
I also like At this point what do I need to do? |
nikomatsakis
commented
Jun 14, 2017
I think we should settle on the name -- I am not 100% sure when we should merge this RFC though. The insta-stable thing bothers me, but I don't have a good idea what else to do about it. |
nikomatsakis
commented
Jun 14, 2017
@rust-lang/lang @rust-lang/libs -- anybody care to "weigh in" on the name of the "error type" to use in the |
kennytm
commented
Jun 14, 2017
If we follow the naming practice in libstd, it should be |
withoutboats
commented
Jun 14, 2017
What's the reason not to use |
kennytm
commented
Jun 14, 2017
@withoutboatsrust-lang/rfcs#1859 explained why the error must be a dedicated type (to prevent accidentally ?-returning an |
huntiep
commented
Jun 15, 2017
I think Any thoughts on how to better document this, regardless of what the final name is? |
alexcrichton
commented
Jun 15, 2017
Ergonomically at least this seems most likely to arise in something like: implFrom<Missing>forMyErrorType(if at all). That way you could |
sfackler
commented
Jun 15, 2017
|
nikomatsakis
commented
Jun 15, 2017
The feeling was that enumList<T>{Nil,Cons(T,Box<List<T>>),}Imagine that I implemented |
nikomatsakis
commented
Jun 15, 2017
👍 for "The error type that results from applying the try operator ( |
nikomatsakis
commented
Sep 28, 2017
@huntiep I took the liberty of rebasing for you. |
huntiep
commented
Sep 29, 2017
@nikomatsakis I'm sorry, I missed that part of your last comment. For future reference, can you briefly explain what you meant by rebase? |
shepmaster
commented
Sep 29, 2017
@huntiep it refers to |
shepmaster
commented
Sep 29, 2017
@nikomatsakis did you mean to review at bors? |
aturon
commented
Sep 29, 2017
@bors: r=nikomatsakis |
bors
commented
Sep 29, 2017
📌 Commit e30d92b has been approved by |
bors
commented
Sep 29, 2017
Impl Try for Option This is part of #31436.
bors
commented
Sep 29, 2017
☀️ Test successful - status-appveyor, status-travis |
Short-circuiting internal iteration with Iterator::try_fold & try_rfold These are the core methods in terms of which the other methods (`fold`, `all`, `any`, `find`, `position`, `nth`, ...) can be implemented, allowing Iterator implementors to get the full goodness of internal iteration by only overriding one method (per direction). Based off the `Try` trait, so works with both `Result` and `Option` (:tada: #42526). The `try_fold` rustdoc examples use `Option` and the `try_rfold` ones use `Result`. AKA continuing in the vein of PRs #44682 & #44856 for more of `Iterator`. New bench following the pattern from the latter of those: ``` test iter::bench_take_while_chain_ref_sum ... bench: 1,130,843 ns/iter (+/- 25,110) test iter::bench_take_while_chain_sum ... bench: 362,530 ns/iter (+/- 391) ``` I also ran the benches without the `fold` & `rfold` overrides to test their new default impls, with basically no change. I left them there, though, to take advantage of existing overrides and because `AlwaysOk` has some sub-optimality due to #43278 (which 45225 should fix). If you're wondering why there are three type parameters, see issue #45462 Thanks for @bluss for the [original IRLO thread](https://internals.rust-lang.org/t/pre-rfc-fold-ok-is-composable-internal-iteration/4434) and the rfold PR and to @cuviper for adding so many folds, [encouraging me](#45379 (comment)) to make this PR, and finding a catastrophic bug in a pre-review.
This is part of #31436.