Skip to main content

node

Macro node 

Source
node!() { /* proc-macro */ }
Expand description

Export a Rust type implementing nros::Node as the package node.

Phase 212.N.12 — nros::node!() is the canonical name (matches the rclcpp_components / ROS 2 launch.xml <node pkg=…> convention). The legacy nros::node!() macro and Component* trait family were retired in the same phase.

§Emitted items

Per invocation the macro currently emits:

  1. pub fn register(runtime: &mut RuntimeCtx<'_>) -> Result<(), RuntimeError> — the Entry-pkg-callable wrapper that registers the four typed register / init / dispatch / tick trampolines with the runtime by stable pkg name (Phase 212.N.7 step-3.4).
  2. #[unsafe(no_mangle)] pub extern "C" fn __nros_node_<pkg>_dispatch_strategy() -> u8 — Phase 216.A.5 ABI export of the Node’s DispatchStrategy discriminant (<Type as Node>::DISPATCH as u8). Read out-of-tree by nros check (216.D.1) and consumed from a separate compilation unit by the RTIC (216.B.3) / Embassy (216.C.3) dispatch tasks. <pkg> is the value of CARGO_PKG_NAME after sanitize_pkg_name_for_symbol (hyphens → underscores).

§Example

struct Talker;

impl nros::Node for Talker {
    const NAME: &'static str = "talker";

    fn register(ctx: &mut nros::NodeContext<'_>) -> nros::NodeResult<()> {
        let mut node = ctx.create_node(
            nros::NodeId::new("node"),
            nros::NodeOptions::new("talker"),
        )?;
        let _pub = node.create_publisher::<std_msgs::msg::String>(
            nros::EntityId::new("pub_chatter"),
            "chatter",
        )?;
        Ok(())
    }
}

nros::node!(Talker);