Skip to main content

dds_topic

Function dds_topic 

Source
pub fn dds_topic(fqn: &str, kind: EntityKind) -> Option<String>
Expand description

Maps a fully qualified ROS 2 name to its DDS topic name.

§Arguments

  • fqn - a fully qualified name (starting with /).
  • kind - the subsystem, which selects the DDS prefix.

§Returns

Some(dds_name) such as rt/cmd_vel, formed by prepending the subsystem prefix to the name; None if fqn is not fully qualified.

§Examples

use pamoja_ros2::name::{dds_topic, EntityKind};

assert_eq!(dds_topic("/foo", EntityKind::Topic).as_deref(), Some("rt/foo"));
assert_eq!(
    dds_topic("/robot1/camera_left/image_raw", EntityKind::Topic).as_deref(),
    Some("rt/robot1/camera_left/image_raw"),
);
assert_eq!(dds_topic("/add_two_ints", EntityKind::ServiceRequest).as_deref(), Some("rq/add_two_ints"));
assert_eq!(dds_topic("relative", EntityKind::Topic), None); // not fully qualified