Uh oh!
There was an error while loading. Please reload this page.
Option::flatten - #60256
Conversation
rust-highfive
commented
Apr 25, 2019
r? @rkruppe (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Centril
commented
Apr 25, 2019
I think it would be preferable to add this as a method Assigning over to random t-libs member; |
@Centril I agree, a flatten method would be a good idea. Do you think I should add both a flatten method and an |
Centril
commented
Apr 25, 2019
Don't really have an opinion :) |
This comment has been minimized.
This comment has been minimized.
Option<Option<T>> with Into trait.Keruspe
commented
Apr 25, 2019
You probably could use unwrap_or_default instead of matching, couldn't you? |
This comment has been minimized.
This comment has been minimized.
Centril
commented
Apr 25, 2019
That imposes a constraint What you can do instead is |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Centril
commented
Apr 25, 2019
@ethanboxx once you're done with the changes, can you please squash them into a single commit? |
rust-highfive
commented
Apr 25, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
eopb
commented
Apr 25, 2019
@Centril I dont understand this error. Can you explain why this is failing? |
@ethanboxx It seems to me you are getting a type inference error because you are giving the compiler too many options to pick from. Try removing the implementation and that should fix it. |
rust-highfive
commented
Apr 25, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
eopb
commented
Apr 25, 2019
@Centril Whats the best way to solve this new issue. |
ghost
commented
Apr 25, 2019
TL;DR: Add Documentation tests are external to the crate they're testing, so the In other places in the standard library, the |
eopb
commented
Apr 26, 2019
alexcrichton
commented
Apr 26, 2019
Thanks for the PR @ethanboxx! I'm personally a bit wary on adding this method though since I feel like what it morally is striving to do is collapse any amount of inner options, but it doesn't handle, for example, The |
Centril
commented
Apr 26, 2019
Note that this is the same for |
eopb
commented
Apr 26, 2019
@alexcrichton You are correct. My original intention was for it flatten all nested layers, however, it quickly became apparent that it was not possible. I have added extra documentation to clarify this in a similar way |
squashed commit
alexcrichton
commented
Apr 29, 2019
Ok, seems reasonable to me! @bors: r+ |
bors
commented
Apr 29, 2019
📌 Commit fa7ba66 has been approved by |
Option::flatten This PR makes this possible. ```rust assert_eq!(Some(6), Some(Some(6)).flatten()); assert_eq!(Some(6), Some(Some(6)).into()); ```
Centril
commented
Apr 29, 2019
@bors rollup |
Rollup of 9 pull requests Successful merges: - #59946 (Fix equivalent string in escape_default docs) - #60256 (Option::flatten) - #60305 (hir: remove LoweredNodeId) - #60334 (Stabilized vectored IO) - #60353 (Add test not to forget resolved ICE) - #60356 (Stabilize str::as_mut_ptr) - #60358 (Clarify the short explanation of E0207) - #60359 (resolve: Consider erroneous imports used to avoid duplicate diagnostics) - #60360 (Add test case for labeled break in const assignment) Failed merges: r? @ghost
Stabilize `Option::flatten` - PR: rust-lang#60256 - Tracking issue: rust-lang#60258@elahn > I was trying to `flat_map()` and found `map().flatten()` does the trick. This has been on nightly for 4 months, can we stabilise it? @ethanboxx > @Centril Helped me get this merged. What is the stabilization process? @Centril > @ethanboxx I'd just file a PR to stabilize it and we'll ask T-libs to FCP. So here I am. I am was unsure what number to put in `since = "-"` so I copied what someone had done in a recent PR.
Stabilize `Option::flatten` - PR: rust-lang#60256 - Tracking issue: rust-lang#60258@elahn > I was trying to `flat_map()` and found `map().flatten()` does the trick. This has been on nightly for 4 months, can we stabilise it? @ethanboxx > @Centril Helped me get this merged. What is the stabilization process? @Centril > @ethanboxx I'd just file a PR to stabilize it and we'll ask T-libs to FCP. So here I am. I am was unsure what number to put in `since = "-"` so I copied what someone had done in a recent PR.
Add Result<Result<T, E>, E>::flatten -> Result<T, E> This PR makes this possible (modulo type inference): ```rust assert_eq!(Ok(6), Ok(Ok(6)).flatten()); ``` Tracking issue: rust-lang#70142 <sub>largely cribbed directly from <https://github.com/rust-lang/rust/pull/60256></sub>
This PR makes this possible.