mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-20 16:29:31 +00:00
Adds native (zero-CBOR) event support to the Rust generator, mirroring the cpp_native / Go event path: a per-event `add_<wire>_listener` registrar takes a closure, boxes it, and registers it through the bare `<lib>_add_event_listener` (native) entry point. The extern "C" trampoline reads the payload as the raw C-POD struct and hands the consumer a borrowed idiomatic value via from_c — no serialization on the hot path. The node owns the boxed closures in a Mutex<HashMap<id, Box<dyn Any>>> keyed by listener id so they outlive the call, and `remove_event_listener` drops them and calls the bare remove entry point. Event externs are only emitted when the library declares events, so event-free crates stay minimal. Verified end-to-end: the demo registers a listener, echo fires on_echo_fired inline, the typed EchoEvent reaches the closure, and removal returns true. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>