From 3fb8ea57469708ae5094d9bdf34820ed747c5659 Mon Sep 17 00:00:00 2001 From: Nikolai Morin Date: Wed, 5 Oct 2022 13:48:12 +0200 Subject: [PATCH] Add TYPE_NAME constant to messages and make error fields public (#277) --- rosidl_generator_rs/resource/msg_rmw.rs.em | 1 + rosidl_runtime_rs/src/sequence.rs | 6 ++++-- rosidl_runtime_rs/src/string.rs | 6 ++++-- rosidl_runtime_rs/src/traits.rs | 3 +++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/rosidl_generator_rs/resource/msg_rmw.rs.em b/rosidl_generator_rs/resource/msg_rmw.rs.em index ef34567e..24d416d0 100644 --- a/rosidl_generator_rs/resource/msg_rmw.rs.em +++ b/rosidl_generator_rs/resource/msg_rmw.rs.em @@ -102,6 +102,7 @@ impl rosidl_runtime_rs::Message for @(type_name) { } impl rosidl_runtime_rs::RmwMessage for @(type_name) where Self: Sized { + const TYPE_NAME: &'static str = "@(package_name)/@(subfolder)/@(type_name)"; fn get_type_support() -> libc::uintptr_t { // SAFETY: No preconditions for this function. unsafe { rosidl_typesupport_c__get_message_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() } diff --git a/rosidl_runtime_rs/src/sequence.rs b/rosidl_runtime_rs/src/sequence.rs index acef7869..64b5892b 100644 --- a/rosidl_runtime_rs/src/sequence.rs +++ b/rosidl_runtime_rs/src/sequence.rs @@ -75,8 +75,10 @@ pub struct BoundedSequence { /// Error type for [`BoundedSequence::try_new()`]. #[derive(Debug)] pub struct SequenceExceedsBoundsError { - len: usize, - upper_bound: usize, + /// The actual length the sequence would have after the operation. + pub len: usize, + /// The upper bound on the sequence length. + pub upper_bound: usize, } /// A by-value iterator created by [`Sequence::into_iter()`] and [`BoundedSequence::into_iter()`]. diff --git a/rosidl_runtime_rs/src/string.rs b/rosidl_runtime_rs/src/string.rs index e3f5ab6b..305062a1 100644 --- a/rosidl_runtime_rs/src/string.rs +++ b/rosidl_runtime_rs/src/string.rs @@ -102,8 +102,10 @@ pub struct BoundedWString { /// Error type for [`BoundedString::try_from()`] and [`BoundedWString::try_from()`]. #[derive(Debug)] pub struct StringExceedsBoundsError { - len: usize, - upper_bound: usize, + /// The actual length the string would have after the operation. + pub len: usize, + /// The upper bound on the string length. + pub upper_bound: usize, } // ========================= impls for String and WString ========================= diff --git a/rosidl_runtime_rs/src/traits.rs b/rosidl_runtime_rs/src/traits.rs index dc03fef1..4737bd1a 100644 --- a/rosidl_runtime_rs/src/traits.rs +++ b/rosidl_runtime_rs/src/traits.rs @@ -38,6 +38,9 @@ pub trait SequenceAlloc: Sized { /// /// User code never needs to call this trait's method, much less implement this trait. pub trait RmwMessage: Clone + Debug + Default + Send + Sync + Message { + /// A string representation of this message's type, e.g. "geometry_msgs/msg/Twist" + const TYPE_NAME: &'static str; + /// Get a pointer to the correct `rosidl_message_type_support_t` structure. fn get_type_support() -> libc::uintptr_t; }