ros2-types-derive 0.5.3

Derive macros for ROS2 TypeDescription and Ros2Msg traits
Documentation

Derive macros for ROS2 types

This crate provides derive macros and helper macros for ROS2 message types:

  • TypeDescription: Generates type descriptions for ROS2 type hash computation
  • Ros2Msg: Generates ROS2 message bindings (FFI with rcl feature, pure Rust otherwise)
  • ros2_service!: Generates service wrapper types
  • ros2_action!: Generates action wrapper types

Features

  • rcl: Enable FFI code generation for ROS2 C libraries. When disabled, generates pure Rust implementations (Clone, Default, PartialEq, Eq).

Container Attributes

  • #[ros2(package = "pkg_name")] - Specify the ROS2 package name
  • #[ros2(interface_type = "msg|srv|action")] - Specify the interface type (default: "msg")

Field Attributes

  • #[ros2(ros2_type = "byte")] - Override field type (for byte, char, wstring)
  • #[ros2(capacity = 255)] - Specify capacity for bounded strings/sequences
  • #[ros2(default = "0")] - Specify default value

Message Example

use ros2_types_derive::{TypeDescription, Ros2Msg};

#[derive(TypeDescription, Ros2Msg)]
#[ros2(package = "std_msgs", interface_type = "msg")]
#[repr(C)]
pub struct Header {
    pub stamp: Time,
    pub frame_id: String,
}

Service Example

use ros2_types_derive::{Ros2Msg, ros2_service};

#[derive(Ros2Msg)]
#[ros2(package = "example_interfaces", interface_type = "srv")]
#[repr(C)]
pub struct AddTwoInts_Request {
    pub a: i64,
    pub b: i64,
}

#[derive(Ros2Msg)]
#[ros2(package = "example_interfaces", interface_type = "srv")]
#[repr(C)]
pub struct AddTwoInts_Response {
    pub sum: i64,
}

// Generate the service wrapper
ros2_service!(example_interfaces, AddTwoInts);

Action Example

use ros2_types_derive::{Ros2Msg, ros2_action};

#[derive(Ros2Msg)]
#[ros2(package = "example_interfaces", interface_type = "action")]
#[repr(C)]
pub struct Fibonacci_Goal {
    pub order: i32,
}

#[derive(Ros2Msg)]
#[ros2(package = "example_interfaces", interface_type = "action")]
#[repr(C)]
pub struct Fibonacci_Result {
    pub sequence: I32Seq<0>,
}

#[derive(Ros2Msg)]
#[ros2(package = "example_interfaces", interface_type = "action")]
#[repr(C)]
pub struct Fibonacci_Feedback {
    pub partial_sequence: I32Seq<0>,
}

// Generate the action wrapper with all helper types
ros2_action!(example_interfaces, Fibonacci);