Ivan FB 99fdcfdff7
feat(codegen): native Rust generator handles seq / Option / nested
Extends the native Rust marshalling to sequences and optionals (the Rust
counterpart of the cpp_native increment): a field maps to Vec<T> / Option<T>,
the repr(C) mirror gains the matching `{ ptr, len }` / `{ present, value }`
fields, and `to_c` now returns a holder owning the CStrings + C-array backing
(Vec/CString live on the heap, so the C struct's raw pointers survive the move
and the call). `from_c` reads seq/Option back out via slice + present-flag.

Unblocks the timer's complex (seq-of-structs / seq-of-strings / two optionals)
and schedule (three struct params). Verified end-to-end — the demo round-trips
typed ComplexResponse / ScheduleResult.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 18:59:57 +02:00

1.5 KiB

Rust bindings — native (generated)

Generated native (zero-serialization) Rust crate for the timer library — the Rust counterpart of c_bindings / go_bindings / cpp_native_bindings, and the native sibling of the CBOR crate in ../rust_bindings.

File Description
src/ffi.rs #[repr(C)] POD mirrors + extern "C" native entry points.
src/types.rs Idiomatic structs + to_c/from_c (a holder owns the CStrings for the call).
src/api.rs <Lib>Node — methods marshal typed args in / read typed struct returns out; blocking via std::sync::mpsc. No CBOR.
examples/demo.rs A small consumer.
let node = MyTimerNode::new(TimerConfig { name: "my-app".into() })?;
println!("{}", node.version()?);
let r = node.echo(EchoRequest { message: "hello".into(), delay_ms: 5 })?;   // -> EchoResponse

Regenerate with nimble genbindings_rust_native.

Status

Requests are fully supported: scalar / string / bool / float / nested struct and now sequences (Vec) and optionals (Option) — create, version, echo, complex, schedule all generate and round-trip typed values. to_c returns a holder that owns the CStrings and C-array backing (heap, so the C struct's raw pointers stay valid across the move and for the call).

Still to come: native typed events and the native-bare / _cbor reconciliation. Linking is left to the consumer (-L <dir> -l my_timer + rpath, as in examples/demo.rs); a build.rs that compiles the dylib can be added later.