rust-lang / rust-lang/rust

Tracking Issue for Option::get_or_try_insert_with

Open
#143,648 0 comments 7 reactions 1 assignee View on GitHub

@lolbinarycat is already working on this.

Since Jul 8, 2025.

C-tracking-issue T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(option_get_or_try_insert_with)]

This is a tracking issue for the Option::get_or_try_insert_with method

This method offers a convenient way of caching fallible operations, similar to OnceLock::get_or_try_init.

Public API
// core::option

impl Option {

use std::ops::{Residual, Try};
pub fn try_get_or_insert_with<'a, R, F>(
    &'a mut self,
    f: F,
) -> <R::Residual as Residual<&'a mut T>>::TryType
where
    F: FnOnce() -> R,
    R: Try<Output = T, Residual: Residual<&'a mut T>>;
}
Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions
  • None yet.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.