-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Option::get_or_default #82849
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add Option::get_or_default #82849
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
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. |
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. |
ef46040
to
90c77fc
Compare
Changed to unstable |
This comment has been minimized.
This comment has been minimized.
90c77fc
to
1cc8c4d
Compare
Added missing feature flag in the docs example. |
@bors r+ |
📌 Commit 1cc8c4d has been approved by |
…=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.
…=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.
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
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 dovec[n].get_or_default().my_data_method()
. Using anOption
as an inner component of a data structure is probably where the need for this will normally arise.