Skip to content

Commit

Permalink
Add TYPE_NAME constant to messages and make error fields public (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnmm authored Oct 5, 2022
1 parent 3b6c013 commit 3fb8ea5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions rosidl_generator_rs/resource/msg_rmw.rs.em
Original file line number Diff line number Diff line change
Expand Up @@ -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)() }
Expand Down
6 changes: 4 additions & 2 deletions rosidl_runtime_rs/src/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ pub struct BoundedSequence<T: SequenceAlloc, const N: usize> {
/// 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()`].
Expand Down
6 changes: 4 additions & 2 deletions rosidl_runtime_rs/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ pub struct BoundedWString<const N: usize> {
/// 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 =========================
Expand Down
3 changes: 3 additions & 0 deletions rosidl_runtime_rs/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3fb8ea5

Please sign in to comment.