once_cell

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

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

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
40 /100 Fair
Development Activity 4
Maintenance 0
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 82
Code Quality 85
Innovation 70
Learning Curve 85

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 26 apps in this directory

Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,326

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
87
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 6 days ago
Rust
79%
AGPL 3.0

Spacedrive

Collaboration · File Storage

39,292

One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.

View details
84
Repo Health
84
Technical
63
Dependency
Built with
Rust 79%
TypeScript 18%
Updated 2 weeks ago
Rust
46%
MIT

Svix

Automation · Developer Tools

3,463

Open source, self-hostable webhook infrastructure that handles delivery, retries, HMAC signing, and multi-tenant event management so you never have to build a webhooks system from scratch.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
Rust 46%
C# 16%
Updated 1 weeks ago
TypeScript
67%
Apache 2.0

tabularis

Databases · Developer Tools

5,270

Open-source desktop SQL workspace with built-in PostgreSQL, MySQL, and SQLite drivers, SQL notebooks, a visual query builder, and a built-in MCP server for AI agents like Claude and Cursor.

View details
84
Repo Health
89
Technical
66
Dependency
Built with
TypeScript 67%
Rust 31%
Updated 6 days ago
Rust
66%
Apache 2.0

Temps

Analytics · Devops · Monitoring

865

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
81
Repo Health
86
Technical
66
Dependency
Built with
Rust 66%
TypeScript 33%
Updated 1 weeks ago
Rust
79%
Apache 2.0

TensorZero

Ab Testing Experimentation · AI Development · Monitoring

11,708

TensorZero unifies the LLM gateway, observability, evaluation, optimization, and experimentation stack behind a single OpenAI-compatible API, built in Rust for sub-millisecond p99 latency.

View details
53
Repo Health
87
Technical
68
Dependency
Built with
Rust 79%
TypeScript 15%
Updated 4 months ago
Rust
71%
MIT

Trieve

AI Development · Developer Tools · Search

2,721

All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.

View details
42
Repo Health
74
Technical
65
Dependency
Built with
Rust 71%
Updated 9 months ago
Rust
50%
Apache 2.0

Vibe Kanban

AI Agents · AI Code Assistants · Project Management

28,441

A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.

View details
72
Repo Health
75
Technical
63
Dependency
Built with
Rust 50%
TypeScript 46%
Updated 1 months 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