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 Node
s 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,
impl<T> Subscription<T>where
T: Message,
Sourcepub fn topic_name(&self) -> String
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.
Sourcepub fn take(&self) -> Result<(T, MessageInfo), RclrsError>
pub fn take(&self) -> Result<(T, MessageInfo), RclrsError>
Fetches a new message.
When there is no new message, this will return a
SubscriptionTakeFailed
.
Sourcepub fn take_boxed(&self) -> Result<(Box<T>, MessageInfo), RclrsError>
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.
Sourcepub fn take_loaned(
&self,
) -> Result<(ReadOnlyLoanedMessage<'_, T>, MessageInfo), RclrsError>
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,
impl<T> SubscriptionBase for Subscription<T>where
T: Message,
Source§fn handle(&self) -> &SubscriptionHandle
fn handle(&self) -> &SubscriptionHandle
rcl
handle.