rust-lang / rust-lang/rust

Tracking Issue for `OnceCell::new_init`

Open
#159,859 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Feature gate: #![feature(once_cell_new_init)]

This is a tracking issue for OnceCell::new_init, as discussed in the ACP: https://github.com/rust-lang/libs-team/issues/817

Sister Tracking issue for OnceLock::new_init: https://github.com/rust-lang/rust/issues/159860

Currently, it is impossible to create an already initialized version of OnceCell:

  • Without using the From<T> implementation for OnceCell<T>
  • In a const context

This new method aims to solve both of these issues.

Public API
impl<T> OnceCell<T> {
    pub const fn new_init(init_value: T) -> OnceCell<T>;
}
Steps / History

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

Unresolved Questions
  • Should the API name be new_init, or something else? Some alternatives: new_initialized, with_value, ...

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.

Research direction

Start with the ACP in rust-lang/libs-team#817 and the implementation referenced as #160881, then read the feature-lifecycle stabilization guide linked in the issue. The remaining work is tracking the final comment period, stabilization PR, and unresolved API naming question; completion is indicated by those checklist items being resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.