pub unsafe trait Once:
Default
+ Send
+ Sync
+ 'static {
// Required methods
fn once(&self, f: impl FnOnce());
fn is_completed(&self) -> bool;
}Expand description
A synchronization primitive which can be used to run a one-time initialization.
§Safety
Implementations must guarantee that:
Once::onceexecutes the provided closure at most once across all concurrent callers, and blocks all concurrent callers until that single execution completes, establishing an acquire/release synchronization edge from the completion of the closure to the return ofOnce::once.Once::is_completedreturnstrueif and only if an invocation ofOnce::oncehas completed without panicking, establishing an acquire synchronization edge with the completion of that closure.Default::defaultreturns an uncompleted instance for whichOnce::is_completedreturnsfalse.
Required Methods§
Sourcefn once(&self, f: impl FnOnce())
fn once(&self, f: impl FnOnce())
Performs a one-time initialization routine.
The given closure f will be executed if and only if this Once
has not already been completed. Concurrent calls to once block until
initialization finishes.
§Panics
If f panics, the implementation is expected to panic on further
attempts to initialize. Note that Netstack3 is usually used in
panic=abort compilations, so we don’t need anything stronger than that.
Sourcefn is_completed(&self) -> bool
fn is_completed(&self) -> bool
Returns true if some Once::once call has completed successfully.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".