nros_node/session.rs
1//! Concrete session type aliases resolved at compile time.
2//!
3//! Exactly one RMW backend feature must be enabled. The aliases below
4//! map the generic `Session` associated types to the concrete handles
5//! provided by the active backend, eliminating the need for generic
6//! type parameters on `Executor`, `Node`, and entity types.
7
8use nros_rmw::Session;
9
10#[cfg(feature = "rmw-cffi")]
11pub(crate) type ConcreteSession = nros_rmw_cffi::CffiSession;
12#[cfg(all(test, not(feature = "rmw-cffi")))]
13pub(crate) type ConcreteSession = crate::mock::MockSession;
14
15/// RFC-0088 — the serialization format the backend this image links speaks,
16/// as its cross-image identity string.
17///
18/// This is a compile-time constant precisely because the backend is selected at
19/// compile time (see the aliases above): where ROS 2 asks
20/// `rmw_get_serialization_format()` at run time — because it resolves its
21/// typesupport through `dlopen` — nano-ros already knows.
22///
23/// **Only meaningful in a single-backend image.** A bridge image links two
24/// backends and has no single answer; it must ask each session instead.
25pub const IMAGE_SERIALIZATION_FORMAT: &str = <ConcreteSession as Session>::SERIALIZATION_FORMAT;
26
27/// Image-local discriminant for [`IMAGE_SERIALIZATION_FORMAT`]. Used by the
28/// compile-time assertions at entity-creation call sites and by the bridge's
29/// one-byte comparison; never persisted, never compared across images.
30pub const IMAGE_SERIALIZATION_FORMAT_ID: nros_serdes::format::SerializationFormatId =
31 <ConcreteSession as Session>::SERIALIZATION_FORMAT_ID;
32
33/// Concrete publisher handle for the active RMW backend.
34pub type RmwPublisher = <ConcreteSession as Session>::PublisherHandle;
35/// Concrete subscriber handle for the active RMW backend.
36pub type RmwSubscriber = <ConcreteSession as Session>::SubscriptionHandle;
37/// Concrete service server handle for the active RMW backend.
38pub type RmwServiceServer = <ConcreteSession as Session>::ServiceHandle;
39/// Concrete service client handle for the active RMW backend.
40pub type RmwServiceClient = <ConcreteSession as Session>::ClientHandle;