Skip to main content

mecha10_behavior_runtime/
status.rs

1//! Node status types for behavior execution
2//!
3//! This module defines the possible states a behavior node can be in during execution.
4
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
9pub enum NodeStatus {
10    Success,
11
12    Failure,
13
14    #[default]
15    Running,
16}
17
18impl NodeStatus {
19    /// Returns true if the status indicates completion (Success or Failure).
20    ///
21    /// # Example
22    ///
23    /// ```rust
24    /// use mecha10_behavior_runtime::NodeStatus;
25    ///
26    /// assert!(NodeStatus::Success.is_complete());
27    /// assert!(NodeStatus::Failure.is_complete());
28    /// assert!(!NodeStatus::Running.is_complete());
29    /// ```
30    pub fn is_complete(&self) -> bool {
31        matches!(self, NodeStatus::Success | NodeStatus::Failure)
32    }
33
34    /// Returns true if the status is Success.
35    pub fn is_success(&self) -> bool {
36        matches!(self, NodeStatus::Success)
37    }
38
39    /// Returns true if the status is Failure.
40    pub fn is_failure(&self) -> bool {
41        matches!(self, NodeStatus::Failure)
42    }
43
44    /// Returns true if the status is Running.
45    pub fn is_running(&self) -> bool {
46        matches!(self, NodeStatus::Running)
47    }
48}
49
50impl fmt::Display for NodeStatus {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        match self {
53            NodeStatus::Success => write!(f, "Success"),
54            NodeStatus::Failure => write!(f, "Failure"),
55            NodeStatus::Running => write!(f, "Running"),
56        }
57    }
58}