Skip to main content

Subscription

Struct Subscription 

Source
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 into M: 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>

Source

pub fn try_recv(&mut self) -> Result<Option<M>, NodeError>

Try to receive a typed message (non-blocking).

Source

pub fn try_recv_raw(&mut self) -> Result<Option<usize>, NodeError>

Try to receive raw CDR-encoded data (non-blocking).

Source

pub fn buffer(&self) -> &[u8]

Get the receive buffer (valid after try_recv_raw).

Source

pub fn supports_event(&self, kind: EventKind) -> bool

true if the active backend can fire the named event for this subscriber.

Source

pub fn on_liveliness_changed<F>(&mut self, cb: F) -> Result<(), NodeError>
where F: FnMut(LivelinessChangedStatus) + Send + 'static,

Register a callback for LivelinessChanged. Fires when a tracked publisher’s liveliness state changes.

Source

pub fn on_requested_deadline_missed<F>( &mut self, deadline: Duration, cb: F, ) -> Result<(), NodeError>
where F: FnMut(CountStatus) + Send + 'static,

Register a callback for RequestedDeadlineMissed. Fires when an expected sample doesn’t arrive within deadline.

Source

pub fn on_message_lost<F>(&mut self, cb: F) -> Result<(), NodeError>
where F: FnMut(CountStatus) + Send + 'static,

Register a callback for MessageLost. Fires when the backend drops a sample (overflow, etc.).

Source

pub fn has_data(&self) -> bool

Check if data is available without consuming it.

Source

pub fn process_in_place( &mut self, f: impl FnOnce(&M), ) -> Result<bool, NodeError>

Process the received message in-place without copying.

Source

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 */
}
Source

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 */
}

Trait Implementations§

Source§

impl<M, const RX_BUF: usize> Drop for Subscription<M, RX_BUF>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<M, const RX_BUF: usize> Freeze for Subscription<M, RX_BUF>

§

impl<M, const RX_BUF: usize> RefUnwindSafe for Subscription<M, RX_BUF>
where M: RefUnwindSafe,

§

impl<M, const RX_BUF: usize = { crate::config::DEFAULT_RX_BUF_SIZE }> !Send for Subscription<M, RX_BUF>

§

impl<M, const RX_BUF: usize = { crate::config::DEFAULT_RX_BUF_SIZE }> !Sync for Subscription<M, RX_BUF>

§

impl<M, const RX_BUF: usize> Unpin for Subscription<M, RX_BUF>
where M: Unpin,

§

impl<M, const RX_BUF: usize> UnsafeUnpin for Subscription<M, RX_BUF>

§

impl<M, const RX_BUF: usize> UnwindSafe for Subscription<M, RX_BUF>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.