Skip to content

Commit bc425d3

Browse files
committed
OnceCell & OnceLock docs: Using set/empty consistently
1 parent 5e55679 commit bc425d3

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

library/core/src/cell/once.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{fmt, mem};
66
/// This allows obtaining a shared `&T` reference to its inner value without copying or replacing
77
/// it (unlike [`Cell`]), and without runtime borrow checks (unlike [`RefCell`]). However,
88
/// only immutable references can be obtained unless one has a mutable reference to the cell
9-
/// itself. In the same vein, the cell can only be re-initialized with such a mutable reference.
9+
/// itself. In the same vein, the cell can only be re-set with such a mutable reference.
1010
///
1111
/// For a thread-safe version of this struct, see [`std::sync::OnceLock`].
1212
///
@@ -68,7 +68,7 @@ impl<T> OnceCell<T> {
6868
/// # Errors
6969
///
7070
/// This method returns `Ok(())` if the cell was empty and `Err(value)` if
71-
/// it was full.
71+
/// it was set.
7272
///
7373
/// # Examples
7474
///
@@ -98,7 +98,7 @@ impl<T> OnceCell<T> {
9898
/// # Errors
9999
///
100100
/// This method returns `Ok(&value)` if the cell was empty and
101-
/// `Err(&current_value, value)` if it was full.
101+
/// `Err(&current_value, value)` if it was set.
102102
///
103103
/// # Examples
104104
///
@@ -130,15 +130,15 @@ impl<T> OnceCell<T> {
130130
Ok(slot.insert(value))
131131
}
132132

133-
/// Gets the contents of the cell, initializing it with `f`
133+
/// Gets the contents of the cell, setting it with `f`
134134
/// if the cell was empty.
135135
///
136136
/// # Panics
137137
///
138138
/// If `f` panics, the panic is propagated to the caller, and the cell
139-
/// remains uninitialized.
139+
/// remains empty.
140140
///
141-
/// It is an error to reentrantly initialize the cell from `f`. Doing
141+
/// It is an error to reentrantly set the cell from `f`. Doing
142142
/// so results in a panic.
143143
///
144144
/// # Examples
@@ -164,12 +164,12 @@ impl<T> OnceCell<T> {
164164
}
165165

166166
/// Gets the mutable reference of the contents of the cell,
167-
/// initializing it with `f` if the cell was empty.
167+
/// setting it with `f` if the cell was empty.
168168
///
169169
/// # Panics
170170
///
171171
/// If `f` panics, the panic is propagated to the caller, and the cell
172-
/// remains uninitialized.
172+
/// remains empty.
173173
///
174174
/// # Examples
175175
///
@@ -199,16 +199,16 @@ impl<T> OnceCell<T> {
199199
}
200200
}
201201

202-
/// Gets the contents of the cell, initializing it with `f` if
202+
/// Gets the contents of the cell, setting it with `f` if
203203
/// the cell was empty. If the cell was empty and `f` failed, an
204204
/// error is returned.
205205
///
206206
/// # Panics
207207
///
208208
/// If `f` panics, the panic is propagated to the caller, and the cell
209-
/// remains uninitialized.
209+
/// remains empty.
210210
///
211-
/// It is an error to reentrantly initialize the cell from `f`. Doing
211+
/// It is an error to reentrantly set the cell from `f`. Doing
212212
/// so results in a panic.
213213
///
214214
/// # Examples
@@ -238,14 +238,14 @@ impl<T> OnceCell<T> {
238238
self.try_init(f)
239239
}
240240

241-
/// Gets the mutable reference of the contents of the cell, initializing
241+
/// Gets the mutable reference of the contents of the cell, setting
242242
/// it with `f` if the cell was empty. If the cell was empty and `f` failed,
243243
/// an error is returned.
244244
///
245245
/// # Panics
246246
///
247247
/// If `f` panics, the panic is propagated to the caller, and the cell
248-
/// remains uninitialized.
248+
/// remains empty.
249249
///
250250
/// # Examples
251251
///
@@ -256,7 +256,7 @@ impl<T> OnceCell<T> {
256256
///
257257
/// let mut cell: OnceCell<u32> = OnceCell::new();
258258
///
259-
/// // Failed initializers do not change the value
259+
/// // Failed sets do not change the value
260260
/// assert!(cell.get_mut_or_try_init(|| "not a number!".parse()).is_err());
261261
/// assert!(cell.get().is_none());
262262
///
@@ -319,9 +319,9 @@ impl<T> OnceCell<T> {
319319
self.inner.into_inner()
320320
}
321321

322-
/// Takes the value out of this `OnceCell`, moving it back to an uninitialized state.
322+
/// Takes the value out of this `OnceCell`, moving it back to an empty state.
323323
///
324-
/// Has no effect and returns `None` if the `OnceCell` hasn't been initialized.
324+
/// Has no effect and returns `None` if the `OnceCell` hasn't been set.
325325
///
326326
/// Safety is guaranteed by requiring a mutable reference.
327327
///

library/std/src/sync/once_lock.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<T> OnceLock<T> {
141141

142142
/// Gets the reference to the underlying value.
143143
///
144-
/// Returns `None` if the cell is empty, or being initialized. This
144+
/// Returns `None` if the cell is empty, or being set. This
145145
/// method never blocks.
146146
#[inline]
147147
#[stable(feature = "once_cell", since = "1.70.0")]
@@ -168,7 +168,7 @@ impl<T> OnceLock<T> {
168168
}
169169
}
170170

171-
/// Blocks the current thread until the cell is initialized.
171+
/// Blocks the current thread until the cell is set.
172172
///
173173
/// # Example
174174
///
@@ -198,8 +198,8 @@ impl<T> OnceLock<T> {
198198

199199
/// Sets the contents of this cell to `value`.
200200
///
201-
/// May block if another thread is currently attempting to initialize the cell. The cell is
202-
/// guaranteed to contain a value when set returns, though not necessarily the one provided.
201+
/// May block if another thread is currently attempting to set the cell. The cell is
202+
/// guaranteed to contain a value when `set` returns, though not necessarily the one provided.
203203
///
204204
/// Returns `Ok(())` if the cell's value was set by this call.
205205
///
@@ -233,10 +233,10 @@ impl<T> OnceLock<T> {
233233
/// Sets the contents of this cell to `value` if the cell was empty, then
234234
/// returns a reference to it.
235235
///
236-
/// May block if another thread is currently attempting to initialize the cell. The cell is
237-
/// guaranteed to contain a value when set returns, though not necessarily the one provided.
236+
/// May block if another thread is currently attempting to set the cell. The cell is
237+
/// guaranteed to contain a value when `set` returns, though not necessarily the one provided.
238238
///
239-
/// Returns `Ok(&value)` if the cell was empty and `Err(&current_value, value)` if it was full.
239+
/// Returns `Ok(&value)` if the cell was empty and `Err(&current_value, value)` if it was set.
240240
///
241241
/// # Examples
242242
///
@@ -269,19 +269,19 @@ impl<T> OnceLock<T> {
269269
}
270270
}
271271

272-
/// Gets the contents of the cell, initializing it with `f` if the cell
272+
/// Gets the contents of the cell, setting it with `f` if the cell
273273
/// was empty.
274274
///
275275
/// Many threads may call `get_or_init` concurrently with different
276-
/// initializing functions, but it is guaranteed that only one function
276+
/// setting functions, but it is guaranteed that only one function
277277
/// will be executed.
278278
///
279279
/// # Panics
280280
///
281281
/// If `f` panics, the panic is propagated to the caller, and the cell
282-
/// remains uninitialized.
282+
/// remains empty.
283283
///
284-
/// It is an error to reentrantly initialize the cell from `f`. The
284+
/// It is an error to reentrantly set the cell from `f`. The
285285
/// exact outcome is unspecified. Current implementation deadlocks, but
286286
/// this may be changed to a panic in the future.
287287
///
@@ -307,15 +307,15 @@ impl<T> OnceLock<T> {
307307
}
308308
}
309309

310-
/// Gets the mutable reference of the contents of the cell, initializing
310+
/// Gets the mutable reference of the contents of the cell, setting
311311
/// it with `f` if the cell was empty.
312312
///
313313
/// This method never blocks.
314314
///
315315
/// # Panics
316316
///
317317
/// If `f` panics, the panic is propagated to the caller, and the cell
318-
/// remains uninitialized.
318+
/// remains empty.
319319
///
320320
/// # Examples
321321
///
@@ -345,16 +345,16 @@ impl<T> OnceLock<T> {
345345
}
346346
}
347347

348-
/// Gets the contents of the cell, initializing it with `f` if
348+
/// Gets the contents of the cell, setting it with `f` if
349349
/// the cell was empty. If the cell was empty and `f` failed, an
350350
/// error is returned.
351351
///
352352
/// # Panics
353353
///
354354
/// If `f` panics, the panic is propagated to the caller, and
355-
/// the cell remains uninitialized.
355+
/// the cell remains empty.
356356
///
357-
/// It is an error to reentrantly initialize the cell from `f`.
357+
/// It is an error to reentrantly set the cell from `f`.
358358
/// The exact outcome is unspecified. Current implementation
359359
/// deadlocks, but this may be changed to a panic in the future.
360360
///
@@ -396,7 +396,7 @@ impl<T> OnceLock<T> {
396396
Ok(unsafe { self.get_unchecked() })
397397
}
398398

399-
/// Gets the mutable reference of the contents of the cell, initializing
399+
/// Gets the mutable reference of the contents of the cell, setting
400400
/// it with `f` if the cell was empty. If the cell was empty and `f` failed,
401401
/// an error is returned.
402402
///
@@ -405,7 +405,7 @@ impl<T> OnceLock<T> {
405405
/// # Panics
406406
///
407407
/// If `f` panics, the panic is propagated to the caller, and
408-
/// the cell remains uninitialized.
408+
/// the cell remains empty.
409409
///
410410
/// # Examples
411411
///
@@ -416,7 +416,7 @@ impl<T> OnceLock<T> {
416416
///
417417
/// let mut cell: OnceLock<u32> = OnceLock::new();
418418
///
419-
/// // Failed initializers do not change the value
419+
/// // Failed sets do not change the value
420420
/// assert!(cell.get_mut_or_try_init(|| "not a number!".parse()).is_err());
421421
/// assert!(cell.get().is_none());
422422
///
@@ -460,9 +460,9 @@ impl<T> OnceLock<T> {
460460
self.take()
461461
}
462462

463-
/// Takes the value out of this `OnceLock`, moving it back to an uninitialized state.
463+
/// Takes the value out of this `OnceLock`, moving it back to an empty state.
464464
///
465-
/// Has no effect and returns `None` if the `OnceLock` hasn't been initialized.
465+
/// Has no effect and returns `None` if the `OnceLock` hasn't been set.
466466
///
467467
/// Safety is guaranteed by requiring a mutable reference.
468468
///
@@ -528,7 +528,7 @@ impl<T> OnceLock<T> {
528528

529529
/// # Safety
530530
///
531-
/// The value must be initialized
531+
/// The value must be set
532532
#[inline]
533533
unsafe fn get_unchecked(&self) -> &T {
534534
debug_assert!(self.is_initialized());
@@ -537,7 +537,7 @@ impl<T> OnceLock<T> {
537537

538538
/// # Safety
539539
///
540-
/// The value must be initialized
540+
/// The value must be set
541541
#[inline]
542542
unsafe fn get_unchecked_mut(&mut self) -> &mut T {
543543
debug_assert!(self.is_initialized());

0 commit comments

Comments
 (0)