Skip to content

Commit 3fb8ea5

Browse files
authored
Add TYPE_NAME constant to messages and make error fields public (#277)
1 parent 3b6c013 commit 3fb8ea5

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

rosidl_generator_rs/resource/msg_rmw.rs.em

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl rosidl_runtime_rs::Message for @(type_name) {
102102
}
103103
104104
impl rosidl_runtime_rs::RmwMessage for @(type_name) where Self: Sized {
105+
const TYPE_NAME: &'static str = "@(package_name)/@(subfolder)/@(type_name)";
105106
fn get_type_support() -> libc::uintptr_t {
106107
// SAFETY: No preconditions for this function.
107108
unsafe { rosidl_typesupport_c__get_message_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() }

rosidl_runtime_rs/src/sequence.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ pub struct BoundedSequence<T: SequenceAlloc, const N: usize> {
7575
/// Error type for [`BoundedSequence::try_new()`].
7676
#[derive(Debug)]
7777
pub struct SequenceExceedsBoundsError {
78-
len: usize,
79-
upper_bound: usize,
78+
/// The actual length the sequence would have after the operation.
79+
pub len: usize,
80+
/// The upper bound on the sequence length.
81+
pub upper_bound: usize,
8082
}
8183

8284
/// A by-value iterator created by [`Sequence::into_iter()`] and [`BoundedSequence::into_iter()`].

rosidl_runtime_rs/src/string.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ pub struct BoundedWString<const N: usize> {
102102
/// Error type for [`BoundedString::try_from()`] and [`BoundedWString::try_from()`].
103103
#[derive(Debug)]
104104
pub struct StringExceedsBoundsError {
105-
len: usize,
106-
upper_bound: usize,
105+
/// The actual length the string would have after the operation.
106+
pub len: usize,
107+
/// The upper bound on the string length.
108+
pub upper_bound: usize,
107109
}
108110

109111
// ========================= impls for String and WString =========================

rosidl_runtime_rs/src/traits.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ pub trait SequenceAlloc: Sized {
3838
///
3939
/// User code never needs to call this trait's method, much less implement this trait.
4040
pub trait RmwMessage: Clone + Debug + Default + Send + Sync + Message {
41+
/// A string representation of this message's type, e.g. "geometry_msgs/msg/Twist"
42+
const TYPE_NAME: &'static str;
43+
4144
/// Get a pointer to the correct `rosidl_message_type_support_t` structure.
4245
fn get_type_support() -> libc::uintptr_t;
4346
}

0 commit comments

Comments
 (0)