rust_supervisor/role/lifecycle.rs
1//! Role lifecycle phase labels.
2//!
3//! Lifecycle phase values are used in role errors and diagnostics so adapters
4//! can report where a contract failed.
5
6/// Lifecycle phase reached by a role contract.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum RoleLifecyclePhase {
9 /// Role initialization before the primary body starts.
10 Init,
11 /// Long-running or one-shot role body.
12 Run,
13 /// Bounded worker body.
14 Work,
15 /// Nested supervisor tree construction.
16 BuildTree,
17 /// Completion hook after bounded or one-shot work succeeds.
18 Complete,
19 /// Shutdown hook after runtime cancellation.
20 Shutdown,
21}
22
23impl RoleLifecyclePhase {
24 /// Returns a stable lowercase phase label.
25 ///
26 /// # Arguments
27 ///
28 /// This function has no arguments.
29 ///
30 /// # Returns
31 ///
32 /// Returns a stable lifecycle phase label for diagnostics.
33 ///
34 /// # Examples
35 ///
36 /// ```
37 /// let phase = rust_supervisor::role::lifecycle::RoleLifecyclePhase::Run;
38 /// assert_eq!(phase.as_str(), "run");
39 /// ```
40 pub fn as_str(&self) -> &'static str {
41 match self {
42 Self::Init => "init",
43 Self::Run => "run",
44 Self::Work => "work",
45 Self::BuildTree => "build_tree",
46 Self::Complete => "complete",
47 Self::Shutdown => "shutdown",
48 }
49 }
50}