Skip to main content

Module rust_adapter

Module rust_adapter 

Source
Expand description

Phase 115.L.0 — Generic Rust-trait → C-vtable adapter.

RustBackendAdapter<R> converts any R: nros_rmw::Rmw whose associated types implement the matching Session / Publisher / Subscription / ServiceTrait / ClientTrait traits into a static NrosRmwVtable. Each per-backend cffi crate then collapses to ~10 LOC:

#[unsafe(no_mangle)]
pub extern "C" fn nros_rmw_zenoh_register() -> nros_rmw_cffi::NrosRmwRet {
    nros_rmw_cffi::RustBackendAdapter::<nros_rmw_zenoh::ZenohRmw>::register()
}

§Storage discipline

  • Session: Box::into_raw(Box::new(session)) is stashed in NrosRmwSession::backend_data. close reclaims via Box::from_raw (drops the box, runs Drop, frees the alloc).
  • Publisher / Subscription / Service / Client: same pattern with their respective handle types.

§’static

Every handle must be 'static (the Box outlives the call). We deliberately do not require Send: the C runtime hands the backend_data pointer back to the same caller that minted it, and the executor’s single-thread-per-session invariant matches the Rust trait surface. Zenoh-pico’s ZenohSession, for instance, holds an unmovable *const Context which the upstream library does not mark Send.

§Bounds

All error types must be TransportError (or Into<TransportError>). This matches every in-tree backend today.

Structs§

RustBackendAdapter
Wraps a Rust Rmw backend behind the canonical NrosRmwVtable C ABI. See module docs.

Traits§

RustBackend
Bundle of trait bounds an Rmw backend must satisfy to be exposed through RustBackendAdapter. Implemented automatically for any R: Rmw whose handle types use TransportError and are 'static.