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    pub fn is_complete(&self) -> bool {
21        matches!(self, NodeStatus::Success | NodeStatus::Failure)
22    }
23
24    /// Returns true if the status is Success.
25    pub fn is_success(&self) -> bool {
26        matches!(self, NodeStatus::Success)
27    }
28
29    /// Returns true if the status is Failure.
30    pub fn is_failure(&self) -> bool {
31        matches!(self, NodeStatus::Failure)
32    }
33
34    /// Returns true if the status is Running.
35    pub fn is_running(&self) -> bool {
36        matches!(self, NodeStatus::Running)
37    }
38}
39
40impl fmt::Display for NodeStatus {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        match self {
43            NodeStatus::Success => write!(f, "Success"),
44            NodeStatus::Failure => write!(f, "Failure"),
45            NodeStatus::Running => write!(f, "Running"),
46        }
47    }
48}