Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for OnceCell/Lock::get_mut_or_init #121641

Open
2 of 4 tasks
tisonkun opened this issue Feb 26, 2024 · 1 comment
Open
2 of 4 tasks

Tracking Issue for OnceCell/Lock::get_mut_or_init #121641

tisonkun opened this issue Feb 26, 2024 · 1 comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@tisonkun
Copy link
Contributor

tisonkun commented Feb 26, 2024

Feature gate: #![feature(once_cell_get_mut)]

This is a tracking issue for

  • OnceCell::get_mut_or_init()
  • OnceCell::get_mut_or_try_init()
  • OnceLock::get_mut_or_init()
  • OnceLock::get_mut_or_try_init()

Public API

    pub fn get_mut_or_try_init<F, E>(&mut self, f: F) -> Result<&mut T, E>
    where
        F: FnOnce() -> Result<T, E> { ... }

    pub fn get_mut_or_init<F>(&mut self, f: F) -> &mut T
    where
        F: FnOnce() -> T { ... }

Steps / History

Unresolved Questions

None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html
@tisonkun tisonkun added the C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC label Feb 26, 2024
@jieyouxu jieyouxu added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Feb 28, 2024
@ChayimFriedman2
Copy link
Contributor

The documentation seems wrong?

Many threads may call get_mut_or_init concurrently with different initializing functions, but it is guaranteed that only one function will be executed.

Since it takes &mut self, this is entirely impossible.

The implementation can likewise be simplified a lot by not using any synchronization.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 31, 2024
Fix docs for OnceLock::get_mut_or_init

Removes an incorrect statment about concurrency from the `OnceLock::get_mut_or_init` (tracked in rust-lang#121641) docs.

Fixes rust-lang#128429
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 1, 2024
Rollup merge of rust-lang#128457 - juntyr:once-lock-docs, r=tgross35

Fix docs for OnceLock::get_mut_or_init

Removes an incorrect statment about concurrency from the `OnceLock::get_mut_or_init` (tracked in rust-lang#121641) docs.

Fixes rust-lang#128429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants