finds.dev← search

// the find

matklad/once_cell

★ 2,086 · Rust · Apache-2.0 · updated Mar 2026

Rust library for single assignment cells and lazy statics without macros

once_cell is the crate that gave Rust ergonomic lazy initialization before the standard library caught up. It provides OnceCell and Lazy types that do what lazy_static does but without macros, with cleaner ownership semantics. As of Rust 1.70, the core types landed in std, so the crate is now mostly a compatibility shim and a home for the remaining unstable variants.

The API design is genuinely good — set() takes &self and returns Result<(), T>, which means you get the value back if the cell was already filled rather than silently dropping it. The sync and unsync split is honest about what you actually need rather than defaulting everyone to atomic overhead. Multiple backing implementations (imp_std, imp_pl, imp_cs) let it work across no_std targets by swapping the synchronization primitive. The influence on std speaks for itself: this is where OnceLock and LazyLock in std 1.70 came from.

The crate is largely superseded by std — if you're on Rust 1.80+ you probably don't need this at all, and the README buries that fact in a single sentence at the bottom. There's no async OnceCell here (that's a separate crate, async_once_cell), which is the thing people actually want now that async Rust is everywhere. The 'race' module, which provides a racy but lock-free OnceCell for primitive types, is genuinely useful but underdocumented compared to the main types.

View on GitHub →

// want more like this?

Every week we dig through GitHub and send you a few repos picked for what you're working on, each with an honest take like this one. Free. See a real issue →

// similar repos

Search the finds →