Struct std::sync::OnceStable
[-] [+]
[src]
pub struct Once { // some fields omitted }
A synchronization primitive which can be used to run a one-time global
initialization. Useful for one-time initialization for FFI or related
functionality. This type can only be constructed with the ONCE_INIT
value.
Example
fn main() { use std::sync::{Once, ONCE_INIT}; static START: Once = ONCE_INIT; START.call_once(|| { // run initialization here }); }use std::sync::{Once, ONCE_INIT}; static START: Once = ONCE_INIT; START.call_once(|| { // run initialization here });
Methods
impl Once
fn call_once<F>(&'static self, f: F) where F: FnOnce()
Perform an initialization routine once and only once. The given closure
will be executed if this is the first time call_once
has been called,
and otherwise the routine will not be invoked.
This method will block the calling task if another initialization routine is currently running.
When this function returns, it is guaranteed that some initialization has run and completed (it may not be the closure specified).