1use std::num::NonZeroU32;
8
9use crate::{DefinitionError, DefinitionTokenKind, definition_token, validate_token};
10
11pub const MAX_PARTITIONS: u16 = 1_024;
13definition_token!(
14 NodeId,
15 DefinitionTokenKind::Node,
16 "A stable logical identifier for one flow-graph node.
17
18Logical identity survives display-name changes. Runtime and database
19identifiers are never node identifiers."
20);
21#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
26pub struct StartLimit(NonZeroU32);
27
28impl StartLimit {
29 pub const UNRESTRICTED: Self = Self(NonZeroU32::MAX);
31
32 pub fn new(value: u32) -> Result<Self, DefinitionError> {
39 NonZeroU32::new(value)
40 .map(Self)
41 .ok_or(DefinitionError::ZeroStartLimit)
42 }
43
44 #[must_use]
46 pub const fn get(self) -> u32 {
47 self.0.get()
48 }
49}
50
51impl Default for StartLimit {
52 fn default() -> Self {
53 Self::UNRESTRICTED
54 }
55}
56
57#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
64#[non_exhaustive]
65pub enum RestartPolicy {
66 #[default]
68 Restartable,
69 NotRestartable,
71}
72
73impl RestartPolicy {
74 #[must_use]
76 pub const fn is_restartable(self) -> bool {
77 matches!(self, Self::Restartable)
78 }
79}
80
81#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
83pub struct StartControls {
84 start_limit: StartLimit,
85 allow_start_if_complete: bool,
86 restart_policy: RestartPolicy,
87}
88
89impl StartControls {
90 #[must_use]
92 pub const fn new(start_limit: StartLimit, allow_start_if_complete: bool) -> Self {
93 Self {
94 start_limit,
95 allow_start_if_complete,
96 restart_policy: RestartPolicy::Restartable,
97 }
98 }
99
100 #[must_use]
102 pub const fn with_restart_policy(mut self, restart_policy: RestartPolicy) -> Self {
103 self.restart_policy = restart_policy;
104 self
105 }
106
107 #[must_use]
109 pub const fn start_limit(&self) -> StartLimit {
110 self.start_limit
111 }
112
113 #[must_use]
115 pub const fn allow_start_if_complete(&self) -> bool {
116 self.allow_start_if_complete
117 }
118
119 #[must_use]
121 pub const fn restart_policy(&self) -> RestartPolicy {
122 self.restart_policy
123 }
124}
125
126#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
128#[non_exhaustive]
129pub enum TerminalKind {
130 Complete,
132 Fail,
134 Stop,
136}
137
138impl TerminalKind {
139 #[must_use]
141 pub const fn as_str(self) -> &'static str {
142 match self {
143 Self::Complete => "complete",
144 Self::Fail => "fail",
145 Self::Stop => "stop",
146 }
147 }
148}
149
150#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
152pub enum FlowTarget {
153 Node(NodeId),
155 Terminal(TerminalKind),
157}
158
159impl FlowTarget {
160 #[must_use]
162 pub fn sort_key(&self) -> (u8, &str) {
163 match self {
164 Self::Node(id) => (0, id.as_str()),
165 Self::Terminal(kind) => (1, kind.as_str()),
166 }
167 }
168}