Skip to content

Add TYPE_NAME constant to messages and make error fields public #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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