init!() { /* proc-macro */ }Expand description
Declare the NIF library: its module name, exported NIFs, pre-interned atoms, resource types, and lifecycle callbacks. Invoke it exactly once per library.
It generates the nif_init entry point, the load/upgrade/unload
scaffolding (which installs the private-data slot, registers resource types,
and interns the declared atoms — all under a catch_unwind), and the
__otter_atoms table that the atom! macro reads.
§Syntax
otter::init!(
"my_module", // the Erlang module name (required, first)
[add, subtract], // the NIF table — functions marked #[otter::nif]
atoms = [ok, error, not_found = "not found"],
resources = [MyResource, Conn: "conn-v1"],
load = on_load, // optional lifecycle callbacks
upgrade = on_upgrade,
unload = on_unload,
);The first two arguments are positional; everything after is an order-independent keyword entry:
atoms = [name, alias = "beam name", …]— atoms interned once at load (and re-interned on upgrade). Usealias = "…"when the BEAM atom text is not a valid Rust identifier. Names are length-checked (≤255 chars) at compile time. Retrieve with theatom!macro.resources = [Type, Type: "tag", …]— resource types to register. A bareTypeis registered under an ABI-fingerprinted name (no cross-build takeover);Type: "tag"registers under a stable tagged name that opts into hot-upgrade takeover.load = f/upgrade = f/unload = f— lifecycle callbacks.loadandupgradereceive the env and the decodedload_infoterm and returnbool(returnfalseto veto the load);unloadreceives the env and cannot veto. Theirload_raw/upgrade_raw/unload_rawvariants (require therawfeature) additionally hand you the library’suser_priv_datavoid*to manage yourself.allow_panic_abort— a bare flag that opts out of the compile-time guard which otherwise rejects building this crate withpanic = "abort"(abort would bypass otter’s panic interception and crash the VM).