Skip to content

Commit e3d63d7

Browse files
fixup! Explain LazyCell in core::cell overview
1 parent f6960cc commit e3d63d7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

library/core/src/cell.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,16 @@
8484
//!
8585
//! ## `LazyCell<T, F>`
8686
//!
87-
//! A common pattern with OnceCell is, for a given OnceCell, to use a specific function on every
87+
//! A common pattern with OnceCell is, for a given OnceCell, to use the same function on every
8888
//! call to [`OnceCell::get_or_init`] with that cell. This is what is offered by [`LazyCell`],
89-
//! which pairs cells of `T` with functions of `F`, and calls `F` before it yields `&T`.
89+
//! which pairs cells of `T` with functions of `F`, and always calls `F` before it yields `&T`.
9090
//! This happens implicitly by simply attempting to dereference the LazyCell to get its contents,
9191
//! so its use is much more transparent with a place which has been initialized by a constant.
9292
//!
9393
//! More complicated patterns that don't fit this description can be built on `OnceCell<T>` instead.
9494
//!
95-
//! `LazyCell` provides the following methods:
96-
//!
97-
//! - [`LazyCell::force`]: initialize the LazyCell and return a reference.
95+
//! `LazyCell` works by providing an implementation of `impl Deref` that calls the function,
96+
//! so you can just use it by dereference (e.g. `*lazy_cell` or `lazy_cell.deref()`).
9897
//!
9998
//! The corresponding [`Sync`] version of `LazyCell<T, F>` is [`LazyLock<T, F>`].
10099
//!

0 commit comments

Comments
 (0)