[][src]Crate conquer_once

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

Synchronization Primitives

With the std 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.

Lazy

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

Once

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

OnceCell

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

Credits

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.

Modules

raw

Generic 'raw' types exposed through various type aliases.

spin

Synchronized one-time and lazy initialization primitives that use spin-locks in case of concurrent accesses under contention.

Structs

ParkThread

Blocking strategy using low-level and OS reliant parking and un-parking mechanisms.

Enums

TryGetError

Possible error variants of non-blocking fallible get calls.

TryInitError

Possible error variants of non-blocking initialization calls.

Type Definitions

Lazy

A type for lazy initialization of e.g. global static variables, which provides the same functionality as the lazy_static! macro.

Once

A synchronization primitive which can be used to run a one-time global initialization.

OnceCell

An interior mutability cell type which allows synchronized one-time initialization and read-only access exclusively after initialization.