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, PartialEq)]
59pub struct StartControls {
60 start_limit: StartLimit,
61 allow_start_if_complete: bool,
62}
63
64impl StartControls {
65 #[must_use]
67 pub const fn new(start_limit: StartLimit, allow_start_if_complete: bool) -> Self {
68 Self {
69 start_limit,
70 allow_start_if_complete,
71 }
72 }
73
74 #[must_use]
76 pub const fn start_limit(&self) -> StartLimit {
77 self.start_limit
78 }
79
80 #[must_use]
82 pub const fn allow_start_if_complete(&self) -> bool {
83 self.allow_start_if_complete
84 }
85}
86
87#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
89#[non_exhaustive]
90pub enum TerminalKind {
91 Complete,
93 Fail,
95 Stop,
97}
98
99impl TerminalKind {
100 #[must_use]
102 pub const fn as_str(self) -> &'static str {
103 match self {
104 Self::Complete => "complete",
105 Self::Fail => "fail",
106 Self::Stop => "stop",
107 }
108 }
109}
110
111#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
113pub enum FlowTarget {
114 Node(NodeId),
116 Terminal(TerminalKind),
118}
119
120impl FlowTarget {
121 #[must_use]
123 pub fn sort_key(&self) -> (u8, &str) {
124 match self {
125 Self::Node(id) => (0, id.as_str()),
126 Self::Terminal(kind) => (1, kind.as_str()),
127 }
128 }
129}