rclrs

Struct Subscription

Source
pub struct Subscription<T>
where T: Message,
{ pub callback: Mutex<AnySubscriptionCallback<T>>, /* private fields */ }
Expand description

Struct for receiving messages of type T.

There can be multiple subscriptions for the same topic, in different nodes or the same node.

Receiving messages requires the node’s executor to spin.

When a subscription is created, it may take some time to get “matched” with a corresponding publisher.

The only available way to instantiate subscriptions is via Node::create_subscription(), this is to ensure that Nodes can track all the subscriptions that have been created.

Fields§

§callback: Mutex<AnySubscriptionCallback<T>>

The callback function that runs when a message was received.

Implementations§

Source§

impl<T> Subscription<T>
where T: Message,

Source

pub fn topic_name(&self) -> String

Returns the topic name of the subscription.

This returns the topic name after remapping, so it is not necessarily the topic name which was used when creating the subscription.

Source

pub fn take(&self) -> Result<(T, MessageInfo), RclrsError>

Fetches a new message.

When there is no new message, this will return a SubscriptionTakeFailed.

Source

pub fn take_boxed(&self) -> Result<(Box<T>, MessageInfo), RclrsError>

This is a version of take() that returns a boxed message.

This can be more efficient for messages containing large arrays.

Source

pub fn take_loaned( &self, ) -> Result<(ReadOnlyLoanedMessage<'_, T>, MessageInfo), RclrsError>

Obtains a read-only handle to a message owned by the middleware.

When there is no new message, this will return a SubscriptionTakeFailed.

This is the counterpart to Publisher::borrow_loaned_message(). See its documentation for more information.

Trait Implementations§

Source§

impl<T> SubscriptionBase for Subscription<T>
where T: Message,

Source§

fn handle(&self) -> &SubscriptionHandle

Internal function to get a reference to the rcl handle.
Source§

fn execute(&self) -> Result<(), RclrsError>

Tries to take a new message and run the callback with it.

Auto Trait Implementations§

§

impl<T> !Freeze for Subscription<T>

§

impl<T> RefUnwindSafe for Subscription<T>
where T: RefUnwindSafe,

§

impl<T> Send for Subscription<T>

§

impl<T> Sync for Subscription<T>

§

impl<T> Unpin for Subscription<T>
where T: Unpin,

§

impl<T> UnwindSafe for Subscription<T>
where T: 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.