pub type Once = OnceCell<()>;Expand description
A synchronization primitive which can be used to run a one-time global initialization.
This type uses the blocking synchronization mechanism provided by the underlying operating system.
For the API of this type alias, see the generic
OnceCell type.
This is a specialization with T = ().
§Examples
use conquer_once::Once;
static mut GLOBAL: usize = 0;
static INIT: Once = Once::uninit();
fn get_global() -> usize {
// SAFETY: this is safe because the `Once` ensures the `static mut` is
// assigned by only one thread and without data races.
unsafe {
INIT.init_once(|| {
GLOBAL = expensive_computation();
});
GLOBAL
}
}
fn expensive_computation() -> usize {
// ...
}Aliased Type§
pub struct Once { /* private fields */ }