Skip to main content

once

Function once 

Source
pub fn once<T>(init: impl FnOnce() -> T) -> &'static T
where T: 'static + Send + Sync,
Expand description

Lazily-initialized generic static in the DefaultNamespace.

Backed by OnceSlot; the first call with a given T runs init. See NamespaceExt::once.

ยงPrecautions

This function is not marked unsafe, but it can cause some unforeseen effects:

If you fetch the once::<T>(A) with A being initializer in one place and then fetch once::<T>(B) with B being different initializer, it will initialize with whatever invocation was first.