Crate conquer_once

source ·
Expand description

This crate provides a set of synchronized initialization primitives, which are primarily useful for lazy and one-time initialization of static variables.

All types exported through the noblock and spin modules are fully #[no_std] compatible.

Synchronization Primitives

With the std cargo feature enabled (which is the default setting), this crate provides the Once, OnceCell and Lazy types and the equivalents of these types using spin-locks in the spin sub-module.


The Lazy type has the same functionality as the lazy_static! macro, but works without any macros.


This type is very similar to the std::sync::Once type in the standard library, but features a richer API.


A cell type with interior mutability that can be only written to once and only allows read access to the contained data after initialization.


Inspiration for this crate is heavily drawn from once_cell, but features clear distinctions between blocking and non-blocking operations and support for #[no_std] environments out of the box, by offering additional synchronization primitives using spin-locks instead of OS reliant blocking mechanisms. Unlike many other crates, support for the #[no_std] compatible types is not mutually exclusive with using the types relying on the presence of the standard library.

The idea for the implementation of the Once/OnceCell types is also directly inspired by the implementation in the standard library. The reasoning behind re-implementing Once is the fairly restricted and partly unstable API of the version in the standard library.


  • Re-exports of internal generic type for the purpose of accessing their documentation.
  • Synchronized one-time and lazy initialization primitives that permit only non-blocking synchronized initialization operations.
  • Synchronized one-time and lazy initialization primitives that use spin-locks in case of concurrent accesses under contention.


  • Possible error variants of non-blocking fallible get calls.
  • Possible error variants of non-blocking initialization calls.

Type Definitions

  • A type for lazy initialization of e.g. global static variables, which provides the same functionality as the lazy_static! macro.
  • A synchronization primitive which can be used to run a one-time global initialization.
  • An interior mutability cell type which allows synchronized one-time initialization and read-only access exclusively after initialization.