use std::num::NonZeroU32;
use crate::{DefinitionError, DefinitionTokenKind, definition_token, validate_token};
pub const MAX_PARTITIONS: u16 = 1_024;
definition_token!(
NodeId,
DefinitionTokenKind::Node,
"A stable logical identifier for one flow-graph node.
Logical identity survives display-name changes. Runtime and database
identifiers are never node identifiers."
);
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct StartLimit(NonZeroU32);
impl StartLimit {
pub const UNRESTRICTED: Self = Self(NonZeroU32::MAX);
pub fn new(value: u32) -> Result<Self, DefinitionError> {
NonZeroU32::new(value)
.map(Self)
.ok_or(DefinitionError::ZeroStartLimit)
}
#[must_use]
pub const fn get(self) -> u32 {
self.0.get()
}
}
impl Default for StartLimit {
fn default() -> Self {
Self::UNRESTRICTED
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct StartControls {
start_limit: StartLimit,
allow_start_if_complete: bool,
}
impl StartControls {
#[must_use]
pub const fn new(start_limit: StartLimit, allow_start_if_complete: bool) -> Self {
Self {
start_limit,
allow_start_if_complete,
}
}
#[must_use]
pub const fn start_limit(&self) -> StartLimit {
self.start_limit
}
#[must_use]
pub const fn allow_start_if_complete(&self) -> bool {
self.allow_start_if_complete
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum TerminalKind {
Complete,
Fail,
Stop,
}
impl TerminalKind {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Complete => "complete",
Self::Fail => "fail",
Self::Stop => "stop",
}
}
}
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum FlowTarget {
Node(NodeId),
Terminal(TerminalKind),
}
impl FlowTarget {
#[must_use]
pub fn sort_key(&self) -> (u8, &str) {
match self {
Self::Node(id) => (0, id.as_str()),
Self::Terminal(kind) => (1, kind.as_str()),
}
}
}