Skip to content

Commit f571735

Browse files
authored
Implement Message for Box<T: Message> (#235)
1 parent 63c726c commit f571735

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

rosidl_runtime_rs/src/traits.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ pub trait Message: Clone + Debug + Default + 'static + Send + Sync {
144144
fn from_rmw_message(msg: Self::RmwMsg) -> Self;
145145
}
146146

147+
/// Allows boxed values to be used by users in Publishers and Subscriptions.
148+
// See https://github.com/ros2-rust/ros2_rust/pull/235 for a discussion of possible alternatives.
149+
impl<T: Message> Message for Box<T> {
150+
type RmwMsg = T::RmwMsg;
151+
152+
fn into_rmw_message(msg_cow: Cow<'_, Self>) -> Cow<'_, Self::RmwMsg> {
153+
T::into_rmw_message(Cow::Owned(*msg_cow.into_owned()))
154+
}
155+
156+
fn from_rmw_message(msg: Self::RmwMsg) -> Self {
157+
Box::new(T::from_rmw_message(msg))
158+
}
159+
}
160+
147161
/// Trait for services.
148162
///
149163
/// User code never needs to call this trait's method, much less implement this trait.

0 commit comments

Comments
 (0)