nros_rmw/lib.rs
1//! RMW (ROS Middleware) abstraction layer for nros.
2//!
3//! This crate provides the middleware-agnostic transport traits that
4//! backend crates (`nros-rmw-zenoh`, `nros-rmw-xrce`) implement.
5//! Application code depends on these traits, not on a concrete backend,
6//! so the transport can be swapped at compile time via Cargo features.
7//!
8//! # Trait hierarchy
9//!
10//! ```text
11//! Rmw — top-level factory, creates Sessions
12//! └─ Session — connection lifecycle, creates handles
13//! ├─ Publisher — publish serialised messages
14//! ├─ Subscription — receive messages (polling or callback)
15//! ├─ ServiceServer — request/reply (server side)
16//! └─ ServiceClient — request/reply (client side)
17//! ```
18//!
19//! See [`traits`] for the full trait definitions.
20//!
21//! # Features
22//!
23//! - `std` — Enable standard library support
24//! - `alloc` — Enable heap allocation
25//!
26//! # Synchronization Backends
27//!
28//! - `sync-spin` — Use `spin::Mutex` (default, works everywhere)
29//! - `sync-critical-section` — Use critical sections (RTIC/Embassy compatible)
30
31#![no_std]
32
33#[cfg(feature = "std")]
34extern crate std;
35
36#[cfg(feature = "alloc")]
37extern crate alloc;
38
39pub mod custom_transport;
40pub mod event;
41// issue 1551 — the one spelling of a fallible `Box::new` (`Box::try_new` is
42// unstable) for entity-creation paths that have an error return.
43#[cfg(feature = "alloc")]
44pub mod fallible;
45pub mod service_inbox;
46pub mod sync;
47pub mod traits;
48pub mod type_descriptor;
49
50#[cfg(feature = "safety-e2e")]
51pub mod safety;
52
53// Phase 108 — status-event surface.
54pub use event::{
55 CountStatus, DeadlineMissedStatus, EventCallback, EventKind, EventPayload,
56 LivelinessChangedStatus, MessageLostStatus, payload_from_raw,
57};
58
59// Phase 115.A — runtime-pluggable custom transport vtable.
60pub use custom_transport::{
61 NROS_TRANSPORT_OPS_ABI_VERSION_V1, NrosTransportOps, peek_custom_transport,
62 set_custom_transport, take_custom_transport,
63};
64
65// phase-461 W2 -- the caller-owned service inbox seam.
66pub use service_inbox::{CallerInbox, CallerInboxStorage, InboxEntry, ServiceInboxSpec};
67
68// Phase 248 (C2) — generic per-type descriptor registration seam.
69pub use type_descriptor::{
70 TypeDescriptorRegistrar, has_type_descriptor_registrar, register_type_descriptor,
71 set_type_descriptor_registrar,
72};
73
74// Re-export safety types when feature is enabled
75#[cfg(feature = "safety-e2e")]
76pub use safety::{IntegrityStatus, SafetyValidator, crc32};
77
78// Re-export main types
79pub use traits::{
80 ActionEndpointHashes, ActionInfo, ClientTrait, DEPTH_SYSTEM_DEFAULT, DURATION_INFINITE_MS,
81 GraphEndpointInfo, GraphEntityKind, LocatorProtocol, Publisher, QoSDurabilityPolicy,
82 QoSHistoryPolicy, QoSLivelinessPolicy, QoSOverride, QoSOverrideCode, QoSOverrideRole,
83 QoSOverrideValue, QoSPolicyMask, QoSProfile, QoSReliabilityPolicy, QoSSystemDefaults,
84 RefusedLen, Rmw, RmwConfig, ServiceInfo, ServiceRequest, ServiceTrait, Session, SessionMode,
85 Subscription, TopicInfo, Transport, TransportConfig, TransportError, decode_qos_override,
86 decode_qos_override_parts, decode_qos_override_role, decode_qos_override_value,
87 duration_to_qos_ms, locator_protocol, qos_override_policy, qos_override_role, validate_locator,
88};
89
90// Re-export `MessageInfo` from nros-core so backends implementing
91// `Subscription::take_serialized_with_info` don't need their own direct
92// nros-core dep.
93pub use nros_core::MessageInfo;
94// Issue 1495 — and the `Time` its setters take, so a seam that BUILDS a
95// `MessageInfo` from a C backend's `rmw_message_info_t` (nros-rmw-cffi's
96// `take_with_info` dispatch) can name it without a direct nros-core dep.
97pub use nros_core::Time;
98
99// Same reason, one method over: [`Publisher::get_gid`]'s return type is
100// `[u8; PUBLISHER_GID_SIZE]`, so a backend implementing it — or a caller
101// sizing a buffer for it — would otherwise need a direct nros-core dep to
102// name the width of a signature this crate declares. `pad_publisher_gid`
103// rides along because a backend whose identity is narrower than 24 bytes
104// must zero-extend through it rather than inventing its own padding (the
105// phase-467 RMW gap-closure design study's Q1).
106pub use nros_core::{PUBLISHER_GID_SIZE, pad_publisher_gid};
107
108// Phase 99 — zero-copy raw API: SlotLending / SlotBorrowing traits.
109// Backends opt in by impl'ing these (and forwarding their own `lending`
110// feature to `nros-rmw/lending`).
111#[cfg(feature = "lending")]
112pub use traits::{SlotBorrowing, SlotLending};