Skip to main content

run_register

Function run_register 

Source
pub fn run_register<P>(format: &str, body: impl FnOnce())
Expand description

Run a register_* body under std::panic::catch_unwind.

Format wrappers’ register_* entry points are called from extern "C" fn init static initializers (.init_array / __mod_init_func / .CRT$XCU) emitted by the export macros. A panic that escapes those entry points crosses an extern "C" boundary and aborts the host process - a panic = "abort" configuration would do the same. Catching the unwind here turns any panic during registration into a logged diagnostic plus “host sees no plugin,” which is the same outcome a plugin author would expect from a missing bus_layouts declaration.

AssertUnwindSafe is applied internally - the panic is treated as fatal-for-this-plugin, so leaving an Arc ref-count or OnceLock half-set is acceptable: the host won’t load the plugin and the process will exit shortly after registration finishes anyway.