Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option::get_or_default #82849

Merged
merged 2 commits into from
Mar 10, 2021
Merged

Conversation

camsteffen
Copy link
Contributor

@camsteffen camsteffen commented Mar 6, 2021

Tracking issue: #82901

The original issue is #55042, which was closed, but for an invalid reason (see discussion there). Opening this to reconsider (I hope that's okay). It seems like the only gap for Option being "entry-like".

I ran into a need for this method where I had a Vec<Option<MyData>> and wanted to do vec[n].get_or_default().my_data_method(). Using an Option as an inner component of a data structure is probably where the need for this will normally arise.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 6, 2021
@Mark-Simulacrum
Copy link
Member

r? @joshtriplett for T-libs member review

I am not sure this pulls enough weight over the insert_with method, but it's also pretty common to have _default variants in std, so not really opposed.

@joshtriplett
Copy link
Member

This seems reasonable to me. The naming seems consistent with other methods in std.

However, this should not be added as insta-stable. This needs to be marked unstable (the feature-gate name seems fine), and it needs a tracking issue.

r=me if made unstable with a tracking issue.

@camsteffen
Copy link
Contributor Author

Changed to unstable

@rust-log-analyzer

This comment has been minimized.

@camsteffen
Copy link
Contributor Author

Added missing feature flag in the docs example.
Added a usage to the compiler.

@joshtriplett
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 8, 2021

📌 Commit 1cc8c4d has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 8, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 9, 2021
…=joshtriplett

Add Option::get_or_default

Tracking issue: rust-lang#82901

The original issue is rust-lang#55042, which was closed, but for an invalid reason (see discussion there). Opening this to reconsider (I hope that's okay). It seems like the only gap for `Option` being "entry-like".

I ran into a need for this method where I had a `Vec<Option<MyData>>` and wanted to do `vec[n].get_or_default().my_data_method()`. Using an `Option` as an inner component of a data structure is probably where the need for this will normally arise.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 9, 2021
…=joshtriplett

Add Option::get_or_default

Tracking issue: rust-lang#82901

The original issue is rust-lang#55042, which was closed, but for an invalid reason (see discussion there). Opening this to reconsider (I hope that's okay). It seems like the only gap for `Option` being "entry-like".

I ran into a need for this method where I had a `Vec<Option<MyData>>` and wanted to do `vec[n].get_or_default().my_data_method()`. Using an `Option` as an inner component of a data structure is probably where the need for this will normally arise.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#77511 (Add StatementKind::CopyNonOverlapping)
 - rust-lang#79208 (Stabilize `unsafe_op_in_unsafe_fn` lint)
 - rust-lang#82411 (Fixes to ExitStatus and its docs)
 - rust-lang#82733 (Add powerpc-unknown-openbsd target)
 - rust-lang#82802 (Build rustdoc for run-make tests, not just run-make-fulldeps)
 - rust-lang#82849 (Add Option::get_or_default)
 - rust-lang#82908 (:arrow_up: rust-analyzer)
 - rust-lang#82937 (Update README.md to use the correct cmake version number)
 - rust-lang#82938 (Bump tracing-tree dependency)
 - rust-lang#82942 (Don't hardcode the `v1` prelude in diagnostics, to allow for new preludes.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1c3fea2 into rust-lang:master Mar 10, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 10, 2021
@camsteffen camsteffen deleted the option-get-or-default branch March 19, 2021 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants