mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-08-05 14:33:13 +00:00
* rust examples: sync main.rs + tokio main.rs demoing the listener API Adds two bundled examples to the generated Rust crate: - examples/main.rs: sync flow using std::sync::mpsc to bridge a typed on_echo_fired listener into main + a wildcard add_event_listener that uses decode_event_payload::<EchoEvent>(envelope) for the matching event id. - examples/tokio_main.rs: same shape via #[tokio::main] + tokio::sync::mpsc. Bumps generateCargoToml to ship `[dev-dependencies]` with tokio's `rt-multi-thread` + `macros` features so the bundled examples can use #[tokio::main] without polluting the library's runtime profile. Run with `cargo run --example main` (set DYLD_LIBRARY_PATH=<repo> on macOS until build.rs emits an rpath). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * simplify examples --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
timer example
This example is a self-contained Nimble project demonstrating how to import nim-ffi and use the .ffiCtor. / .ffi. abstraction.
Usage
-
Change into the example directory:
cd examples/timer -
Install the local
ffidependency:nimble install -y ../.. -
Build the example library:
nimble build -
Generate bindings:
nimble genbindings_rust nimble genbindings_cpp
Rust example clients
The Rust client lives in examples/timer/rust_client.
-
Run the sync example:
cd examples/timer/rust_client cargo run --bin rust_client -
Run the Tokio example:
cd examples/timer/rust_client cargo run --bin tokio_client
C++ example
The generated C++ example lives in examples/timer/cpp_bindings.
Build and run it with:
cd examples/timer/cpp_bindings
cmake -S . -B build
cmake --build build
./build/example