Ivan FB 7a5ab67831
refactor(codegen): reconcile Rust crate names with the native/cbor convention
Aligns the Rust crate names with the C generator and the symbol naming: the
native (zero-serialization, same-process) crate is the bare `<lib>` and the
CBOR (inter-process) crate carries the `_cbor` suffix — mirroring `<lib>.h` /
`<lib>_cbor.h` and the `<name>` / `<name>_cbor` exports.

Previously the native crate was `<lib>_native` and the CBOR crate was the bare
`<lib>`, which is backwards from the symbol convention. Only the Cargo package
name changes; the linked dylib stays `lib<lib>.dylib` (the `#[link]` name and
build.rs are untouched).

Consumers updated: rust_client depends on `my_timer_cbor` and imports from it;
the native demo imports from the bare `my_timer`.

Validated: rust_client builds against the renamed CBOR crate; the native demo
round-trips version / echo / event / complex / schedule against the bare crate;
check_bindings_rust regen is deterministic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 19:38:35 +02:00
..
2026-05-16 01:08:42 +02:00

Rust Client Examples

Purpose

This folder contains example Rust applications that demonstrate how to use the auto-generated timer crate (from ../rust_bindings).

What's Included

Two executable examples:

  • rust_client — Synchronous example

    • Shows basic synchronous calls to the Nim timer API
    • Uses blocking wait with condition variables
    • Source: src/main.rs
  • tokio_client — Asynchronous example with Tokio runtime

    • Demonstrates the Tokio async runtime integration
    • Uses spawn_blocking to handle the blocking FFI callbacks on a separate thread pool
    • Source: src/tokio_main.rs

Building

cd examples/timer/rust_client
cargo build

Running

# Sync example
cargo run --bin rust_client

# Tokio async example
cargo run --bin tokio_client

Important Notes

  • The timer crate is a local dependency (path = "../rust_bindings")
  • It is auto-generated — do not manually edit it
  • These examples are not part of the generated output; they are hand-written to show usage patterns
  • To regenerate the timer crate, run nimble genbindings_rust from the parent directory