Macro select_once

Source
macro_rules! select_once {
    (
        sig: fn($($arg:ident: $ArgTy:ty),*) -> $RetTy:ty,
        init: $init:expr,
        call: $call:expr,
    ) => { ... };
}
Expand description

Call init once to choose an implementation, then use it for the rest of the program.

  • sig is the function type.
  • init is an expression called at startup that chooses an implementation and returns a function pointer.
  • call is an expression to call a function returned by init, encapsulating any safety preconditions.

The type Func is available in init and call.

This is effectively our version of an ifunc without linker support. Note that init may be called more than once until one completes.