Skip to main content

CallbackCtx

Struct CallbackCtx 

Source
pub struct CallbackCtx<'a> { /* private fields */ }
Expand description

Context handed to an executable component callback body (W.5.1).

Carries the triggering payload (raw CDR — empty for timers) plus the publisher resolver, so a body can read its message and publish immediately. Service / action-result callbacks additionally carry a ReplySink the body fills via reply; action goal / cancel callbacks carry a DecisionSink the body fills via set_goal_response / set_cancel_response (W.5.3).

Implementations§

Source§

impl<'a> CallbackCtx<'a>

Source

pub fn new(payload: &'a [u8], publishers: &'a dyn PublisherResolver) -> Self

Build a callback context with no reply sink (timer / subscription). payload is the entity’s raw CDR (empty slice for timers).

Source

pub fn with_reply( payload: &'a [u8], publishers: &'a dyn PublisherResolver, reply_buf: &'a mut [u8], reply_written: &'a mut usize, ) -> Self

Build a callback context with a reply sink (service / action-result; W.5.3). The body fills reply_buf via reply; the generated trampoline reads *reply_written back as the response length.

Source

pub fn with_goal_decision( payload: &'a [u8], publishers: &'a dyn PublisherResolver, out: &'a mut GoalResponse, ) -> Self

Build a context for an action goal callback (W.5.3): the body decides accept/reject via set_goal_response; the generated trampoline returns *out. payload is the goal CDR.

Source

pub fn with_cancel_decision( payload: &'a [u8], publishers: &'a dyn PublisherResolver, out: &'a mut CancelResponse, ) -> Self

Build a context for an action cancel callback (W.5.3): the body decides accept/reject via set_cancel_response.

Source

pub fn set_goal_response(&mut self, response: GoalResponse) -> NodeResult<()>

Set the action goal-callback’s accept/reject decision (W.5.3). Err when the callback is not a goal decision.

Source

pub fn set_cancel_response( &mut self, response: CancelResponse, ) -> NodeResult<()>

Set the action cancel-callback’s accept/reject decision (W.5.3). Err when the callback is not a cancel decision.

Source

pub fn reply_raw(&mut self, data: &[u8]) -> NodeResult<()>

Write the service / action reply as raw CDR bytes (W.5.3). Err when the callback has no reply sink (timer / subscription) or the reply exceeds the lent buffer.

Source

pub fn reply<M: RosMessage, const N: usize>( &mut self, msg: &M, ) -> NodeResult<()>

Serialize msg and write it as the service / action reply (W.5.3).

Source

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

Raw CDR payload of the triggering message / request. Empty for timers.

Source

pub fn message<M: RosMessage>(&self) -> NodeResult<M>

Deserialize the triggering payload as M (subscription / service-request bodies). Err if the payload is malformed for M.

Source

pub fn publish_to_topic<M: RosMessage, const N: usize>( &self, topic: &str, msg: &M, ) -> NodeResult<()>

Serialize msg and publish through the entity synthesized from topic.

This pairs with DeclaredNode::create_publisher_for_topic, allowing simple callback bodies to use the ROS topic literal instead of restating an unrelated stable entity ID.

Auto Trait Implementations§

§

impl<'a> Freeze for CallbackCtx<'a>

§

impl<'a> !RefUnwindSafe for CallbackCtx<'a>

§

impl<'a> !Send for CallbackCtx<'a>

§

impl<'a> !Sync for CallbackCtx<'a>

§

impl<'a> Unpin for CallbackCtx<'a>

§

impl<'a> UnsafeUnpin for CallbackCtx<'a>

§

impl<'a> !UnwindSafe for CallbackCtx<'a>

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.