Run rustfmt

This commit is contained in:
aeon 2023-06-23 10:45:11 +08:00 committed by Martin Dahl
parent a042dc8c55
commit e8dd2bf9ab
7 changed files with 77 additions and 28 deletions

View File

@ -250,10 +250,24 @@ where
.map_err(|_| Error::RCL_RET_CLIENT_INVALID)
.map(|r| match r {
Ok(r) => match r.return_code {
e if e == action_msgs::srv::CancelGoal::Response::ERROR_NONE as i8 => Ok(()),
e if e == action_msgs::srv::CancelGoal::Response::ERROR_REJECTED as i8 => Err(Error::GoalCancelRejected),
e if e == action_msgs::srv::CancelGoal::Response::ERROR_UNKNOWN_GOAL_ID as i8 => Err(Error::GoalCancelUnknownGoalID),
e if e == action_msgs::srv::CancelGoal::Response::ERROR_GOAL_TERMINATED as i8 => Err(Error::GoalCancelAlreadyTerminated),
e if e == action_msgs::srv::CancelGoal::Response::ERROR_NONE as i8 => {
Ok(())
}
e if e == action_msgs::srv::CancelGoal::Response::ERROR_REJECTED as i8 => {
Err(Error::GoalCancelRejected)
}
e if e
== action_msgs::srv::CancelGoal::Response::ERROR_UNKNOWN_GOAL_ID
as i8 =>
{
Err(Error::GoalCancelUnknownGoalID)
}
e if e
== action_msgs::srv::CancelGoal::Response::ERROR_GOAL_TERMINATED
as i8 =>
{
Err(Error::GoalCancelAlreadyTerminated)
}
x => panic!("unknown error code return from action server: {}", x),
},
Err(e) => Err(e),

View File

@ -217,10 +217,24 @@ impl WrappedActionClientUntyped {
.map_err(|_| Error::RCL_RET_CLIENT_INVALID)
.map(|r| match r {
Ok(r) => match r.return_code {
e if e == action_msgs::srv::CancelGoal::Response::ERROR_NONE as i8 => Ok(()),
e if e == action_msgs::srv::CancelGoal::Response::ERROR_REJECTED as i8 => Err(Error::GoalCancelRejected),
e if e == action_msgs::srv::CancelGoal::Response::ERROR_UNKNOWN_GOAL_ID as i8 => Err(Error::GoalCancelUnknownGoalID),
e if e == action_msgs::srv::CancelGoal::Response::ERROR_GOAL_TERMINATED as i8 => Err(Error::GoalCancelAlreadyTerminated),
e if e == action_msgs::srv::CancelGoal::Response::ERROR_NONE as i8 => {
Ok(())
}
e if e == action_msgs::srv::CancelGoal::Response::ERROR_REJECTED as i8 => {
Err(Error::GoalCancelRejected)
}
e if e
== action_msgs::srv::CancelGoal::Response::ERROR_UNKNOWN_GOAL_ID
as i8 =>
{
Err(Error::GoalCancelUnknownGoalID)
}
e if e
== action_msgs::srv::CancelGoal::Response::ERROR_GOAL_TERMINATED
as i8 =>
{
Err(Error::GoalCancelAlreadyTerminated)
}
x => panic!("unknown error code return from action server: {}", x),
},
Err(e) => Err(e),

View File

@ -26,13 +26,27 @@ impl GoalStatus {
pub fn from_rcl(s: i8) -> Self {
match s {
s if s == crate::action_msgs::msg::GoalStatus::STATUS_UNKNOWN as i8 => GoalStatus::Unknown,
s if s == crate::action_msgs::msg::GoalStatus::STATUS_ACCEPTED as i8 => GoalStatus::Accepted,
s if s == crate::action_msgs::msg::GoalStatus::STATUS_EXECUTING as i8 => GoalStatus::Executing,
s if s == crate::action_msgs::msg::GoalStatus::STATUS_CANCELING as i8 => GoalStatus::Canceling,
s if s == crate::action_msgs::msg::GoalStatus::STATUS_SUCCEEDED as i8 => GoalStatus::Succeeded,
s if s == crate::action_msgs::msg::GoalStatus::STATUS_CANCELED as i8 => GoalStatus::Canceled,
s if s == crate::action_msgs::msg::GoalStatus::STATUS_ABORTED as i8 => GoalStatus::Aborted,
s if s == crate::action_msgs::msg::GoalStatus::STATUS_UNKNOWN as i8 => {
GoalStatus::Unknown
}
s if s == crate::action_msgs::msg::GoalStatus::STATUS_ACCEPTED as i8 => {
GoalStatus::Accepted
}
s if s == crate::action_msgs::msg::GoalStatus::STATUS_EXECUTING as i8 => {
GoalStatus::Executing
}
s if s == crate::action_msgs::msg::GoalStatus::STATUS_CANCELING as i8 => {
GoalStatus::Canceling
}
s if s == crate::action_msgs::msg::GoalStatus::STATUS_SUCCEEDED as i8 => {
GoalStatus::Succeeded
}
s if s == crate::action_msgs::msg::GoalStatus::STATUS_CANCELED as i8 => {
GoalStatus::Canceled
}
s if s == crate::action_msgs::msg::GoalStatus::STATUS_ABORTED as i8 => {
GoalStatus::Aborted
}
_ => panic!("unknown action status: {}", s),
}
}

View File

@ -294,7 +294,8 @@ where
// check if all cancels were rejected.
if requested_cancels >= 1 && response_msg.goals_canceling.is_empty() {
response_msg.return_code = action_msgs::srv::CancelGoal::Response::ERROR_REJECTED as i8;
response_msg.return_code =
action_msgs::srv::CancelGoal::Response::ERROR_REJECTED as i8;
}
responses.push((*request_id, response_msg));
@ -533,7 +534,10 @@ where
let response_msg = if !goal_exists {
// Goal does not exists
let msg = T::make_result_response_msg(action_msgs::msg::GoalStatus::STATUS_UNKNOWN as i8, T::Result::default());
let msg = T::make_result_response_msg(
action_msgs::msg::GoalStatus::STATUS_UNKNOWN as i8,
T::Result::default(),
);
let mut response_msg = WrappedNativeMsg::<
<<T as WrappedActionTypeSupport>::GetResult as WrappedServiceTypeSupport>::Response,
>::from(&msg);
@ -664,7 +668,8 @@ where
action_server.publish_status();
// create result message
let result_msg = T::make_result_response_msg(action_msgs::msg::GoalStatus::STATUS_CANCELED as i8, msg);
let result_msg =
T::make_result_response_msg(action_msgs::msg::GoalStatus::STATUS_CANCELED as i8, msg);
let native_msg = WrappedNativeMsg::<
<<T as WrappedActionTypeSupport>::GetResult as WrappedServiceTypeSupport>::Response,
>::from(&result_msg);
@ -684,7 +689,8 @@ where
action_server.set_goal_state(&self.uuid, rcl_action_goal_event_t::GOAL_EVENT_ABORT)?;
// create result message
let result_msg = T::make_result_response_msg(action_msgs::msg::GoalStatus::STATUS_ABORTED as i8, msg);
let result_msg =
T::make_result_response_msg(action_msgs::msg::GoalStatus::STATUS_ABORTED as i8, msg);
let native_msg = WrappedNativeMsg::<
<<T as WrappedActionTypeSupport>::GetResult as WrappedServiceTypeSupport>::Response,
>::from(&result_msg);
@ -707,7 +713,8 @@ where
action_server.set_goal_state(&self.uuid, rcl_action_goal_event_t::GOAL_EVENT_SUCCEED)?;
// create result message
let result_msg = T::make_result_response_msg(action_msgs::msg::GoalStatus::STATUS_SUCCEEDED as i8, msg);
let result_msg =
T::make_result_response_msg(action_msgs::msg::GoalStatus::STATUS_SUCCEEDED as i8, msg);
let native_msg = WrappedNativeMsg::<
<<T as WrappedActionTypeSupport>::GetResult as WrappedServiceTypeSupport>::Response,
>::from(&result_msg);

View File

@ -132,6 +132,10 @@ pub const ROS_DISTRO: &str = "galactic";
pub const ROS_DISTRO: &str = "humble";
#[cfg(r2r__ros__distro__rolling)]
pub const ROS_DISTRO: &str = "rolling";
#[cfg(not(any(r2r__ros__distro__foxy, r2r__ros__distro__galactic,
r2r__ros__distro__humble, r2r__ros__distro__rolling)))]
#[cfg(not(any(
r2r__ros__distro__foxy,
r2r__ros__distro__galactic,
r2r__ros__distro__humble,
r2r__ros__distro__rolling
)))]
pub const ROS_DISTRO: &str = "unknown";

View File

@ -771,7 +771,6 @@ mod tests {
assert!(!json_request.to_string().is_empty());
}
#[cfg(r2r__action_msgs__msg__GoalStatus)]
#[test]
fn test_msg_constants() {
@ -795,6 +794,5 @@ mod tests {
assert_eq!(1, CancelGoal::Response::ERROR_REJECTED as i8);
assert_eq!(2, CancelGoal::Response::ERROR_UNKNOWN_GOAL_ID as i8);
assert_eq!(3, CancelGoal::Response::ERROR_GOAL_TERMINATED as i8);
}
}

View File

@ -2,8 +2,8 @@ use std::ffi::c_void;
use std::ffi::CString;
use std::fmt::Debug;
use std::marker::PhantomData;
use std::sync::Weak;
use std::sync::Once;
use std::sync::Weak;
use crate::error::*;
use crate::msg_types::*;
@ -181,9 +181,8 @@ where
rcl_borrow_loaned_message(publisher.as_ref(), T::get_ts(), &mut loaned_msg)
};
if ret != RCL_RET_OK as i32 {
// TODO: Switch to logging library
log::error!("Failed getting loaned message");
return Err(Error::from_rcl_error(ret))
return Err(Error::from_rcl_error(ret));
}
let handle_box = Box::new(*publisher.as_ref());
@ -209,7 +208,6 @@ where
} else {
static LOG_LOANED_ERROR: Once = Once::new();
LOG_LOANED_ERROR.call_once(|| {
// TODO: Switch to logging library
log::error!("Currently used middleware can't loan messages. Local allocator will be used.");
});