Macro global_jit_alloc

Source
macro_rules! global_jit_alloc {
    ($static_var:path) => { ... };
    (unsafe $provider:block) => { ... };
}
Available on crate feature global_jit_alloc and non-crate feature default_jit_alloc only.
Expand description

Defines a global JitAlloc implementation which GlobalJitAlloc will defer to.

The macro can either take a path to a static variable or an unsafe block resolving to a &'static JitAlloc:

static GLOBAL_JIT: MyJitAlloc = MyJitAlloc::new();
global_jit_alloc!(GLOBAL_JIT);
use std::sync::OnceLock;

global_jit_alloc!(unsafe {
    static WRAPPED_JIT: OnceLock<MyJitAlloc> = OnceLock::new();
    WRAPPED_JIT.get_or_init(|| MyJitAlloc::new())
});

The block form must be marked with unsafe as sometimes returning a different impl can lead to UB, and you are responsible to make sure this doesn’t happen.