ros2_types/lib.rs
1//! ROS2 type support library
2//!
3//! This crate provides core traits and utilities for ROS2 message types,
4//! including RIHS01 (ROS Interface Hashing Standard v1) type hash calculation.
5//!
6//! # Features
7//!
8//! - `derive`: Enable derive macros for `TypeDescription` and `Ros2Msg`
9//! - `native`: Enable native CDR serialization (for Zenoh, iceoryx2, etc.)
10//!
11//! # Traits
12//!
13//! This crate provides several traits for ROS2 message types:
14//!
15//! - `TypeSupport`: For types with type support information and CDR serialization
16//! - `TryClone`: For types that can fail cloning (FFI types)
17//! - `ServiceMsg`: For ROS2 service types (Request/Response pairs)
18//! - `ActionMsg`: For ROS2 action types (Goal/Result/Feedback)
19//! - `ActionGoal`, `ActionResult`: For action service types
20//! - `GetUUID`, `GoalResponse`, `ResultResponse`: Helper traits for actions
21//!
22//! # Native CDR Serialization
23//!
24//! When the `native` feature is enabled, message types can be serialized/deserialized
25//! using CDR encoding (compatible with DDS/ROS2):
26//!
27//! ```ignore
28//! use ros2_types::TypeSupport;
29//!
30//! let msg = std_msgs::msg::String { data: "hello".into() };
31//! let bytes = msg.to_bytes()?;
32//! let decoded = std_msgs::msg::String::from_bytes(&bytes)?;
33//! ```
34//!
35//! **Note**: When using `native` feature, message structs must derive
36//! `serde::Serialize` and `serde::Deserialize`.
37
38pub mod cdr;
39mod error;
40mod hash;
41mod ros_field_type;
42mod traits;
43
44mod type_description;
45pub mod types;
46
47pub use cdr::CdrSerde;
48pub use error::{Error, Result};
49pub use hash::{calculate_type_hash, parse_rihs_string};
50pub use ros_field_type::RosFieldType;
51pub use traits::{
52 ActionGoal, ActionMsg, ActionResult, GetUUID, GoalResponse, ResultResponse, SequenceRaw,
53 ServiceMsg, TryClone, TypeSupport, UnsafeDuration, UnsafeTime,
54};
55pub use type_description::{
56 ActionTypeDescription, MessageTypeName, ServiceTypeDescription, TypeDescription,
57};
58pub use types::{
59 FIELD_TYPE_BOOLEAN, FIELD_TYPE_BOUNDED_STRING, FIELD_TYPE_BOUNDED_WSTRING, FIELD_TYPE_BYTE,
60 FIELD_TYPE_CHAR, FIELD_TYPE_DOUBLE, FIELD_TYPE_FIXED_STRING, FIELD_TYPE_FIXED_WSTRING,
61 FIELD_TYPE_FLOAT, FIELD_TYPE_INT8, FIELD_TYPE_INT16, FIELD_TYPE_INT32, FIELD_TYPE_INT64,
62 FIELD_TYPE_LONG_DOUBLE, FIELD_TYPE_NESTED_TYPE, FIELD_TYPE_NOT_SET, FIELD_TYPE_STRING,
63 FIELD_TYPE_UINT8, FIELD_TYPE_UINT16, FIELD_TYPE_UINT32, FIELD_TYPE_UINT64, FIELD_TYPE_WCHAR,
64 FIELD_TYPE_WSTRING,
65};
66
67// Note: Field, FieldType, IndividualTypeDescription, TypeDescriptionMsg are NOT re-exported
68// at the crate root to avoid conflicts with generated type_description_interfaces messages.
69// Access them via ros2_types::types::{Field, FieldType, ...} if needed.
70
71#[cfg(feature = "derive")]
72pub use ros2_types_derive::{
73 ActionTypeDescription, Ros2Msg, ServiceTypeDescription, TypeDescription, ros2_action,
74 ros2_service,
75};
76
77// Re-export cdr-encoding dependencies for generated code
78pub use serde;
79pub use serde_big_array::BigArray;