r2r/
action_common.rs
1#[derive(Debug, Copy, Clone, PartialEq, Eq)]
3pub enum GoalStatus {
4 Unknown,
5 Accepted,
6 Executing,
7 Canceling,
8 Succeeded,
9 Canceled,
10 Aborted,
11}
12
13impl GoalStatus {
14 #[allow(dead_code)]
15 pub fn to_rcl(&self) -> i8 {
16 match self {
17 GoalStatus::Unknown => crate::action_msgs::msg::GoalStatus::STATUS_UNKNOWN as i8,
18 GoalStatus::Accepted => crate::action_msgs::msg::GoalStatus::STATUS_ACCEPTED as i8,
19 GoalStatus::Executing => crate::action_msgs::msg::GoalStatus::STATUS_EXECUTING as i8,
20 GoalStatus::Canceling => crate::action_msgs::msg::GoalStatus::STATUS_CANCELING as i8,
21 GoalStatus::Succeeded => crate::action_msgs::msg::GoalStatus::STATUS_SUCCEEDED as i8,
22 GoalStatus::Canceled => crate::action_msgs::msg::GoalStatus::STATUS_CANCELED as i8,
23 GoalStatus::Aborted => crate::action_msgs::msg::GoalStatus::STATUS_ABORTED as i8,
24 }
25 }
26
27 pub fn from_rcl(s: i8) -> Self {
28 match s {
29 s if s == crate::action_msgs::msg::GoalStatus::STATUS_UNKNOWN as i8 => {
30 GoalStatus::Unknown
31 }
32 s if s == crate::action_msgs::msg::GoalStatus::STATUS_ACCEPTED as i8 => {
33 GoalStatus::Accepted
34 }
35 s if s == crate::action_msgs::msg::GoalStatus::STATUS_EXECUTING as i8 => {
36 GoalStatus::Executing
37 }
38 s if s == crate::action_msgs::msg::GoalStatus::STATUS_CANCELING as i8 => {
39 GoalStatus::Canceling
40 }
41 s if s == crate::action_msgs::msg::GoalStatus::STATUS_SUCCEEDED as i8 => {
42 GoalStatus::Succeeded
43 }
44 s if s == crate::action_msgs::msg::GoalStatus::STATUS_CANCELED as i8 => {
45 GoalStatus::Canceled
46 }
47 s if s == crate::action_msgs::msg::GoalStatus::STATUS_ABORTED as i8 => {
48 GoalStatus::Aborted
49 }
50 _ => panic!("unknown action status: {}", s),
51 }
52 }
53}
54
55impl std::fmt::Display for GoalStatus {
56 fn fmt(&self, fmtr: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 let s = match self {
58 GoalStatus::Unknown => "unknown",
59 GoalStatus::Accepted => "accepted",
60 GoalStatus::Executing => "executing",
61 GoalStatus::Canceling => "canceling",
62 GoalStatus::Succeeded => "succeeded",
63 GoalStatus::Canceled => "canceled",
64 GoalStatus::Aborted => "aborted",
65 };
66
67 write!(fmtr, "{}", s)
68 }
69}