- Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
Note: lazy_cell_consume is now tracked at #125623
This supercedes #74465 after a portion of once_cell was stabilized with #105587
Feature gate: #![feature(lazy_cell)]
This is a tracking issue for the LazyCell and LazyLock types, which are designed to support convenient one-time initialization. One of the main goals is to be able to replace the lazy_static crate, as well as once_cell::{sync, unsync}::Lazy.
Public API
// core::cell (in core/src/cell/lazy.rs) pub struct LazyCell<T, F = fn() -> T> { /* ... */ } impl<T, F: FnOnce() -> T> LazyCell<T, F> { pub const fn new(init: F) -> LazyCell<T, F>; pub fn force(this: &LazyCell<T, F>) -> &T; } impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> { type Target = T; } impl<T: Default> Default for LazyCell<T>; impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F>;// std::sync (in std/sync/lazy_lock.rs) pub struct LazyLock<T, F = fn() -> T> { /* ... */ } impl<T, F: FnOnce() -> T> LazyLock<T, F> { pub const fn new(f: F) -> LazyLock<T, F>; pub fn force(this: &LazyLock<T, F>) -> &T; } impl<T, F> Drop for LazyLock<T, F>; impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> { type Target = T; } impl<T: Default> Default for LazyLock<T>; impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F>; // We never create a `&F` from a `&LazyLock<T, F>` so it is fine // to not impl `Sync` for `F` unsafe impl<T: Sync + Send, F: Send> Sync for LazyLock<T, F>; // auto-derived `Send` impl is OK. impl<T: RefUnwindSafe + UnwindSafe, F: UnwindSafe> RefUnwindSafe for LazyLock<T, F>; impl<T: UnwindSafe, F: UnwindSafe> UnwindSafe for LazyLock<T, F>;Steps / History
- Implementation: Add lazy initialization primitives to std #72414
- Final comment period (FCP)1
- Stabilization PR - Stabilize
LazyCellandLazyLock#121377
Unresolved Questions
- Is variance of Lazy correct? (See Feature request: Make
Lazy<T, F>covariant inFmatklad/once_cell#167) - Default
F = fn() -> Tin type signature (See Tracking Issue forlazy_cell#109736 (comment))
Footnotes
tuguzT, Flash1232, andrewbanchich, attila-lin, CeleritasCelery and 65 more
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.