Move location of from_rcl_error to avoid the need for r2r::Error to be Clone

This commit is contained in:
Michael Hoy 2023-12-13 22:51:57 +08:00
parent 2e17b8ed40
commit f5ba556e2e
2 changed files with 4 additions and 4 deletions

View File

@ -11,7 +11,7 @@ pub type Result<T> = std::result::Result<T, Error>;
/// These values are mostly copied straight from the RCL headers, but
/// some are specific to r2r, such as `GoalCancelRejected` which does
/// not have an analogue in the rcl.
#[derive(Error, Debug, Clone)]
#[derive(Error, Debug)]
pub enum Error {
#[error("RCL_RET_OK")]
RCL_RET_OK,

View File

@ -36,7 +36,7 @@ pub(crate) fn uuid_msg_to_uuid(msg: &unique_identifier_msgs::msg::UUID) -> uuid:
// TODO where is the best place for this?
thread_local! {
pub static SERIALIZED_MESSAGE_CACHE: Result<RefCell<rcl_serialized_message_t>> = {
pub static SERIALIZED_MESSAGE_CACHE: std::result::Result<RefCell<rcl_serialized_message_t>, i32> = {
use r2r_rcl::*;
let mut msg_buf: rcl_serialized_message_t = unsafe { rcutils_get_zero_initialized_uint8_array() };
@ -50,7 +50,7 @@ thread_local! {
};
if ret != RCL_RET_OK as i32 {
Err(Error::from_rcl_error(ret))
Err(ret)
} else {
Ok(RefCell::new(msg_buf))
}
@ -94,7 +94,7 @@ pub trait WrappedTypesupport:
SERIALIZED_MESSAGE_CACHE.with(|msg_buf| {
let msg_buf: &mut rcl_serialized_message_t = &mut *msg_buf.as_ref().map_err(|err| err.clone())?.borrow_mut();
let msg_buf: &mut rcl_serialized_message_t = &mut *msg_buf.as_ref().map_err(|err| Error::from_rcl_error(*err))?.borrow_mut();
let result = unsafe {
rmw_serialize(