Skip to content

Migrate from lazy_static crate to std::sync::LazyLock #448

@jaudiger

Description

@jaudiger

lazy_static!, while a declarative macro, is a macro nonetheless. It can add quite a bit of additional compilation time cost. once_cell::sync::Lazy does the same thing with generics, and can be used more flexibly (i.e. non-static lazily initialised values), and has been proposed to be added to std: rust-lang/rfcs#2788.

Famous Rust projects already did the transition, such as:

Edit: Since the opening of this issue, a lot of things has happened in Rust, and with Rust 1.80.0, std::sync::LazyLock has been stabilised (see https://doc.rust-lang.org/std/sync/struct.LazyLock.html). There is no need anymore to rely on a crate to lazy initialised a value that is thread safe, everything can now be managed from Rust std 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions