Skip to content

Tracking Issue for lazy_cell #109736

@tgross35

Description

@tgross35

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

Unresolved Questions

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions