Skip to content

OnceCell docs: empty/full terminology v.s. (un)initialized #85716

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

Closed
SimonSapin opened this issue May 26, 2021 · 12 comments · Fixed by #136289
Closed

OnceCell docs: empty/full terminology v.s. (un)initialized #85716

SimonSapin opened this issue May 26, 2021 · 12 comments · Fixed by #136289
Assignees
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. Libs-Small Libs issues that are considered "small" or self-contained T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

SimonSapin commented May 26, 2021

Documentation at:

Appears to use "empty" and "uninitialized" interchangeably to describe the state of a given cell, and similarly "full" and "initialized". I think it’d be better to pick one set of terminology and stick to it consistently. Using empty/full might be better because "uninitialized" terminology is already used for std::mem::MaybeUninit, and manipulating an empty cell does not have the memory-safety risks of reading bytes from MaybeUninit::uninit().

@SimonSapin SimonSapin added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. Libs-Small Libs issues that are considered "small" or self-contained labels May 26, 2021
@camsteffen
Copy link
Contributor

"initialized" corresponds with the API methods like get_or_init. I think that particular consistency is more important.

@Cyborus04
Copy link
Contributor

What about get_or or get_or_with instead?

@hkBst
Copy link
Member

hkBst commented Jan 27, 2025

Given links are dangling, but I think this is about:

I believe the states should be called empty and initialized, with the transition being initializing.
Thus:

  • uninitialized should be replaced by empty
  • full should be replaced by initialized

@hkBst
Copy link
Member

hkBst commented Jan 27, 2025

@rustbot labels: +E-easy

@rustbot rustbot added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Jan 27, 2025
@Pyr0de
Copy link
Contributor

Pyr0de commented Jan 29, 2025

I believe the states should be called empty and initialized, with the transition being initializing. Thus:

* uninitialized should be replaced by empty

* full should be replaced by initialized

Hey,
If this is terminology that is preferred, I could make the changes.

@rustbot claim

@hkBst
Copy link
Member

hkBst commented Jan 29, 2025

@Pyr0de it's just my informed opinion, and what I would do (you may find out when your PR gets reviewed that other people disagree or not). BTW I think "full" should be replaced by something like "already initialized". Anyway use your best judgment! Good luck.

@Pyr0de
Copy link
Contributor

Pyr0de commented Jan 29, 2025

pub fn set(&self, value: T) -> Result<(), T>

Sets the contents of the cell to value.

Hey,
Since OnceCell already has functions like set and it also uses "sets" in its docs, I could replace

  • "empty" with "unset" / "not set"
  • "initialized" with "set"

Example: "Creates a new unset cell"

Or does this change the meaning?

@hkBst
Copy link
Member

hkBst commented Jan 29, 2025

@Pyr0de I think that would also be fine.

@Pyr0de
Copy link
Contributor

Pyr0de commented Jan 30, 2025

Should I also change the comments to match the changes or just the docs?

@hkBst
Copy link
Member

hkBst commented Jan 30, 2025

@Pyr0de if you are talking about comments in code examples, then yes change those to match as well.

@Pyr0de
Copy link
Contributor

Pyr0de commented Jan 30, 2025

I did make the changes in the code example comments.
I was wondering if I had to make changes in the code comments left for explaining the code, not part of the docs

@hkBst
Copy link
Member

hkBst commented Jan 30, 2025

@Pyr0de I'm not sure what you mean by "code comments left for explaining the code, not part of the docs". Ah do you mean like ordinary non-doc comments? Ideally yes.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 3, 2025
OnceCell & OnceLock docs: Using (un)initialized consistently

Changed
* `set` / `initialize` / `full` to `initialized state`
* `uninitialize` / `empty` to `uninitialized state`
* `f` to `f()`
* Added explaination of `uninitialized state` & `initialized state`

[OnceCell Docs](https://doc.rust-lang.org/nightly/std/cell/struct.OnceCell.html)
[OnceLock Docs](https://doc.rust-lang.org/nightly/std/sync/struct.OnceLock.html)

Fixes rust-lang#85716
`@rustbot` label +A-docs
@bors bors closed this as completed in f2b7a29 Feb 4, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 4, 2025
Rollup merge of rust-lang#136289 - Pyr0de:oncecell-docs, r=tgross35

OnceCell & OnceLock docs: Using (un)initialized consistently

Changed
* `set` / `initialize` / `full` to `initialized state`
* `uninitialize` / `empty` to `uninitialized state`
* `f` to `f()`
* Added explaination of `uninitialized state` & `initialized state`

[OnceCell Docs](https://doc.rust-lang.org/nightly/std/cell/struct.OnceCell.html)
[OnceLock Docs](https://doc.rust-lang.org/nightly/std/sync/struct.OnceLock.html)

Fixes rust-lang#85716
``@rustbot`` label +A-docs
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this issue Mar 11, 2025
OnceCell & OnceLock docs: Using (un)initialized consistently

Changed
* `set` / `initialize` / `full` to `initialized state`
* `uninitialize` / `empty` to `uninitialized state`
* `f` to `f()`
* Added explaination of `uninitialized state` & `initialized state`

[OnceCell Docs](https://doc.rust-lang.org/nightly/std/cell/struct.OnceCell.html)
[OnceLock Docs](https://doc.rust-lang.org/nightly/std/sync/struct.OnceLock.html)

Fixes rust-lang#85716
``@rustbot`` label +A-docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. Libs-Small Libs issues that are considered "small" or self-contained T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants