rust-lang / rust-lang/rust

Tracking Issue for `OnceLock::new_init`

Open
#159,860 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_lock_new_init)]

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

Sister Tracking issue for OnceCell::new_init: https://github.com/rust-lang/rust/issues/159859

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

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

This new method aims to solve both of these issues.

Public API
impl<T> OnceLock<T> {
    pub const fn new_init(init_value: T) -> OnceLockl<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 by reading the implementation referenced as #160881 and the ACP at rust-lang/libs-team#817, then review the unresolved API naming question. The tracking work is done when the final comment period completes and a stabilization PR is opened.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.