Tracking Issue for Option::get_or_insert_default
· Issue #82901 · rust-lang/rust
Navigation Menu
- [GitHub Copilot
Write better code with AI](https://github.com/features/copilot)
- [GitHub Copilot
[GitHub Advanced Security
Find and fix vulnerabilities](https://github.com/security/advanced-security)[Actions
Automate any workflow](https://github.com/features/actions)[Codespaces
Instant dev environments](https://github.com/features/codespaces)[Issues
Plan and track work](https://github.com/features/issues)[Code Review
Manage code changes](https://github.com/features/code-review)[Discussions
Collaborate outside of code](https://github.com/features/discussions)[Code Search
Find more, search less](https://github.com/features/code-search)Explore
- [GitHub Sponsors
Fund open source developers](https://github.com/sponsors)
- [GitHub Sponsors
[The ReadME Project
GitHub community articles](https://github.com/readme)- [Enterprise platform
AI-powered developer platform](https://github.com/enterprise)
- [Enterprise platform
Use saved searches to filter your results more quickly
Description
Feature gate: #![feature(option_get_or_insert_default)]
This is a tracking issue for adding Option::get_or_insert_default
.
Basically, it is a shorthand for option.get_or_insert_with(Default::default)
. It differs with unwrap_or_default
since it does not consume the Option
. This is useful, for example, when you have an Option
as a struct field or inside a data structure like Vec<Option<T>>
.
Public API
impl<T> Option<T> {
pub fn get_or_insert_default(&mut self) -> &mut T where T: Default;
}
Steps / History
- Original issue: Option should have method
get_or_default
#55042 - Implementation: Add Option::get_or_default #82849
- Renamed from
get_or_default
toget_or_insert_default
: RenameOption::get_or_default
toget_or_insert_default
#82977 - Final commenting period (FCP)
- Stabilization PR
Unresolved Questions
- None yet.