once_cell

Single-assignment cells and lazy statics for Rust, without macros or unsafe code

Library
Cargo
v1.21.4
2,088stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity8
Maintenance0
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality85
Innovation70
Learning Curve85

once_cell provides OnceCell<T> and Lazy<T> types that can be assigned at most once, giving Rust code a safe way to perform one-time initialization of a value and then read it directly afterward — no unsafe, no macro-based indirection. It ships both a single-threaded unsync::OnceCell for non-shared state and a thread-safe sync::OnceCell/Lazy pair built on atomics (optionally backed by parking_lot for a smaller cell size), plus a race module of lock-free cells for no_std environments.

For years it was the de facto replacement for the lazy_static! macro and for hand-rolled unsafe global statics in the Rust ecosystem, and much of its sync API was eventually adopted into the standard library as std::sync::OnceLock/std::cell::OnceCell (stabilized in Rust 1.70). The crate remains widely depended on both for its Lazy type (which the standard library still lacks) and by codebases that predate or don’t want to bump their MSRV past the stabilization version.

What You Get

  • unsync::OnceCell<T> for single-threaded, non-Sync lazy initialization
  • sync::OnceCell<T> and sync::Lazy<T> for thread-safe one-time initialization backed by atomics
  • A race module of lock-free cells (OnceBox, etc.) for no_std targets via the alloc/portable-atomic/critical-section features
  • Optional parking_lot backend to shrink OnceCell<T>’s in-memory size
  • A stable, macro-free API surface that predates and substantially overlaps with the now-stabilized std::sync::OnceLock

Common Use Cases

  • Replacing lazy_static! macro usage with a macro-free, more ergonomic Lazy<T> static
  • Caching an expensive-to-compute value (parsed config, compiled regex, computed table) behind a single initialization point
  • Providing global, thread-safe application state that’s initialized once at first access rather than at program start
  • Implementing no_std/embedded one-time initialization via the race/critical-section feature set

Under The Hood

Architecture - The crate is split into unsync (in lib.rs) for single-threaded use and sync, backed by one of three interchangeable low-level implementations selected via Cargo features: imp_std.rs (atomics + std::sync primitives, ~415 lines), imp_pl.rs (a parking_lot_core-based implementation that trades a dependency for a smaller cell size), or imp_cs.rs (a critical-section-based implementation for no_std/embedded targets); a separate race.rs module implements lock-free “racy” cells (e.g. OnceBox) for contexts where blocking synchronization isn’t available. Tech Stack - Pure Rust (edition 2021, MSRV 1.65) with all synchronization dependencies gated behind opt-in features (parking_lot_core, portable-atomic, critical-section) so the default build depends on nothing beyond std; a xtask workspace member handles crate housekeeping. Code Quality - tests/ covers reentrant-init deadlock scenarios, cross-thread synchronization races, and no_std builds, and the examples/ directory includes purpose-built benchmarks (bench.rs, bench_acquire.rs) and a deadlock-reproduction example (reentrant_init_deadlocks.rs) that documents a known hazard of recursive initialization; the crate has a long, stable history with careful semver discipline. API Design - The API is deliberately minimal — get, set, get_or_init on OnceCell, and transparent Deref on Lazy — closely mirroring what later became std::sync::OnceLock, so most users can adopt it with almost no learning curve, and migrating to or from the standard-library equivalent is largely mechanical.

Used by 21 apps in this directory

Dart
74%
AGPL 3.0

AppFlowy

Productivity · Project Management · Collaboration

75,729

The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.

View details
66
Repo Health
81
Technical
66
Dependency
Built with
Dart74%
Rust24%
Updated 1 weeks ago
Go
32%
Apache 2.0

CubeSandbox

Developer Tools · Security · AI Agents

11,247

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
83
Repo Health
88
Technical
63
Dependency
Built with
Go32%
Rust31%
C21%
Updated today
Rust
100%
Other

Fluree DB

Databases

445

A temporal, verifiable graph database with git-like branching, integrated vector/text/geo search, and RDF/SPARQL/JSON-LD/openCypher support — benchmarked at 10.4x faster than the next database on the full Wikidata dump.

View details
86
Repo Health
74
Technical
65
Dependency
Built with
Rust100%
Updated yesterday
Rust
95%
MIT

Fyrox

Game Development

9,512

A production-ready 2D/3D game engine written in Rust with a built-in scene editor, physics, and hot-reloading game scripts

View details
85
Repo Health
79
Technical
68
Dependency
Built with
Rust95%
Updated yesterday
Rust
57%
MIT

Handy

Productivity

29,916

Free, offline, open-source speech-to-text that pastes directly into any app on Windows, macOS, and Linux.

View details
87
Repo Health
78
Technical
73
Dependency
Built with
Rust57%
TypeScript31%
Updated today
Go
62%
MIT

hoop

Security · Monitoring

791

A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.

View details
86
Repo Health
80
Technical
66
Dependency
Built with
Go62%
Clojure20%
JavaScript10%
Updated yesterday
Rust
72%
Other

iii

Developer Tools · Devops

18,604

Compose, extend, and observe every backend service in real time using three primitives: Workers, Functions, and Triggers.

View details
86
Repo Health
85
Technical
69
Dependency
Built with
Rust72%
TypeScript17%
Updated yesterday
TypeScript
76%
Other

Joplin

Note Taking

56,003

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
62
Dependency
Built with
TypeScript76%
JavaScript15%
Updated yesterday
JavaScript
57%
Other

Lokus

Note Taking · Knowledge Management

774

Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.

View details
78
Repo Health
75
Technical
65
Dependency
Built with
JavaScript57%
HTML24%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search