pub struct Subscription<M, const RX_BUF: usize = { crate::config::DEFAULT_RX_BUF_SIZE }> { /* private fields */ }Expand description
Typed subscription handle with internal receive buffer.
Two methods, both byte-oriented at the wire:
try_recv/recv— pull bytes from the backend, CDR-decode intoM: RosMessage, hand back ownership of the typed message.try_recv_raw— copy bytes into the subscription’s internal buffer and return the length, leaving CDR decoding to the caller.
No typed borrow() exists. Borrow lives exclusively on
RawSubscription. RecvView is &[u8] semantics; CDR decoding
into a typed M requires owning the bytes (or running the decoder
in place), which the borrow contract doesn’t fit. See
docs/design/0010-zero-copy-raw-api.md decision D7.
Implementations§
Source§impl<M: RosMessage, const RX_BUF: usize> Subscription<M, RX_BUF>
impl<M: RosMessage, const RX_BUF: usize> Subscription<M, RX_BUF>
Sourcepub fn try_recv(&mut self) -> Result<Option<M>, NodeError>
pub fn try_recv(&mut self) -> Result<Option<M>, NodeError>
Try to receive a typed message (non-blocking).
Sourcepub fn try_recv_raw(&mut self) -> Result<Option<usize>, NodeError>
pub fn try_recv_raw(&mut self) -> Result<Option<usize>, NodeError>
Try to receive raw CDR-encoded data (non-blocking).
Sourcepub fn supports_event(&self, kind: EventKind) -> bool
pub fn supports_event(&self, kind: EventKind) -> bool
true if the active backend can fire the named event for this
subscriber.
Sourcepub fn on_liveliness_changed<F>(&mut self, cb: F) -> Result<(), NodeError>
pub fn on_liveliness_changed<F>(&mut self, cb: F) -> Result<(), NodeError>
Register a callback for LivelinessChanged. Fires when a
tracked publisher’s liveliness state changes.
Sourcepub fn on_requested_deadline_missed<F>(
&mut self,
deadline: Duration,
cb: F,
) -> Result<(), NodeError>
pub fn on_requested_deadline_missed<F>( &mut self, deadline: Duration, cb: F, ) -> Result<(), NodeError>
Register a callback for RequestedDeadlineMissed. Fires when
an expected sample doesn’t arrive within deadline.
Sourcepub fn on_message_lost<F>(&mut self, cb: F) -> Result<(), NodeError>
pub fn on_message_lost<F>(&mut self, cb: F) -> Result<(), NodeError>
Register a callback for MessageLost. Fires when the backend
drops a sample (overflow, etc.).
Sourcepub fn process_in_place(
&mut self,
f: impl FnOnce(&M),
) -> Result<bool, NodeError>
pub fn process_in_place( &mut self, f: impl FnOnce(&M), ) -> Result<bool, NodeError>
Process the received message in-place without copying.
Sourcepub async fn recv(&mut self) -> Result<M, NodeError>
pub async fn recv(&mut self) -> Result<M, NodeError>
Async: wait for the next message (no futures dependency needed).
Requires a background task running executor.spin_async() to drive
I/O. Returns Ok(msg) on the next received message, or Err if the
transport reports an error.
When the stream feature is enabled, prefer StreamExt::next() /
TryStreamExt::try_next() for combinator support.
§Example
let mut sub = node.create_subscription::<Int32>("/topic")?;
loop {
let msg = sub.recv().await?;
/* handle msg */
}Sourcepub fn wait_next(
&mut self,
executor: &mut Executor,
timeout: Duration,
) -> Result<Option<M>, NodeError>
pub fn wait_next( &mut self, executor: &mut Executor, timeout: Duration, ) -> Result<Option<M>, NodeError>
Sync: wait for the next message, spinning the executor.
Returns Ok(Some(msg)) if a message arrives within timeout_ms,
or Ok(None) on timeout. Unlike Promise::wait(), timeout is
not an error — the caller typically retries in a loop.
§Example
while let Some(msg) = sub.wait_next(&mut executor, core::time::Duration::from_millis(1000))? {
/* handle msg */
}