Repository navigation
Conversation
|
We have a bunch of methods about iterators of results: I think Now, do we want to add those shortcuts? That's the question. @jswrenn What do you think? EDIT: The documentation of sum (same for product) mention panics. It would do the same here.
I failed to read the documentation once but if this is not mentioned then someone will have a problem. |
Done! |
Done! |
| /// Ok(()) | ||
| /// } | ||
| /// ``` | ||
| fn product_ok<T, U, E>(self) -> Result<U, E> |
There was a problem hiding this comment.
Hm, this is an inelegantly large number of generic arguments.
This is a fairly radical alternative, but: What if we just mirrored the stdlib Try trait? We can pub-in-priv our Try-fork so that folks don't end up explicitly depending on it, and then simply (and potentially non-breaking-ly!) switch over to the standard library Try once it's stabilized.
If we do this, our *_ok functions will support more than just Results, and they'll be able to take just one generic argument, rather than three (I think).
Thoughts, @Philippe-Cholet and @phimuemue?
There was a problem hiding this comment.
There was a problem hiding this comment.
That sure is radical but interesting, maybe it should have its own issue.
About the names, *_ok now and try_* later? (or maybe_*?!)
After a quick look, ControlFlow requires 1.55+ while we currently have 1.43. Unless we copy it too?
I previously read something about #[track_caller] but don't remember much about its use.
In libcore, fold is usually specialized using try_fold specializations alongside with NeverShortCircuit which surely won't be public forever so I thought that we would copy it at some point.
`.product_ok()` is a more convenient way of writing `.product::<Result<_, _>>()` `.sum_ok()` is a more convenient way of writing `.sum::<Result<_, _>>()`
|
@Philippe-Cholet @jswrenn Any thoughts on merging this PR to add |
|
Hi there @sjackman, thanks for bringing this up, and sorry for taking so long. We (more or less) established the guideline to avoid these "convenience methods" (there are several other similar PRs that we did not merge). Following that, I'll close this PR. |
.product_ok()is a more convenient way of writing.product::<Result<_, _>>().sum_ok()is a more convenient way of writing.sum::<Result<_, _>>()Modelled after
.try_collect()