Skip to main content

Once

Trait Once 

Source
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:

  1. Once::once executes 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 of Once::once.
  2. Once::is_completed returns true if and only if an invocation of Once::once has completed without panicking, establishing an acquire synchronization edge with the completion of that closure.
  3. Default::default returns an uncompleted instance for which Once::is_completed returns false.

Required Methods§

Source

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.

Source

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".

Implementations on Foreign Types§

Source§

impl Once for Once

Source§

fn once(&self, f: impl FnOnce())

Source§

fn is_completed(&self) -> bool

Implementors§