qubit_state_machine/fast/fast_state_machine_build_error.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10
11//! Validation errors returned while building a fast state machine.
12
13use thiserror::Error;
14
15/// Error returned when fast state machine configuration is invalid.
16#[derive(Debug, Clone, Copy, Eq, PartialEq, Error)]
17pub enum FastStateMachineBuildError {
18 /// State count was not configured.
19 #[error("state count is not configured")]
20 StateCountNotConfigured,
21
22 /// Event count was not configured.
23 #[error("event count is not configured")]
24 EventCountNotConfigured,
25
26 /// State count must be greater than zero.
27 #[error("state count must be positive: {count}")]
28 InvalidStateCount {
29 /// Requested state count.
30 count: usize,
31 },
32
33 /// Event count must be greater than zero.
34 #[error("event count must be positive: {count}")]
35 InvalidEventCount {
36 /// Requested event count.
37 count: usize,
38 },
39
40 /// Transition transition-table size overflowed `usize`.
41 #[error("transition table overflowed usize: {state_count} * {event_count}")]
42 TransitionTableOverflow {
43 /// The number of states.
44 state_count: usize,
45
46 /// The number of events.
47 event_count: usize,
48 },
49
50 /// An initial state code exceeds the configured state count.
51 #[error("initial state is out of range: {state} >= {state_count}")]
52 InitialStateOutOfRange {
53 /// The invalid initial state.
54 state: usize,
55 /// Configured state count.
56 state_count: usize,
57 },
58
59 /// A final state code exceeds the configured state count.
60 #[error("final state is out of range: {state} >= {state_count}")]
61 FinalStateOutOfRange {
62 /// The invalid final state.
63 state: usize,
64 /// Configured state count.
65 state_count: usize,
66 },
67
68 /// A transition source code exceeds the configured state count.
69 #[error("transition source is out of range: {source_state} >= {state_count}")]
70 TransitionSourceOutOfRange {
71 /// The invalid source state.
72 source_state: usize,
73 /// Configured state count.
74 state_count: usize,
75 },
76
77 /// A transition event code exceeds the configured event count.
78 #[error("transition event is out of range: {event} >= {event_count}")]
79 TransitionEventOutOfRange {
80 /// The invalid event code.
81 event: usize,
82 /// Configured event count.
83 event_count: usize,
84 },
85
86 /// A transition target code exceeds the configured state count.
87 #[error("transition target is out of range: {target} >= {state_count}")]
88 TransitionTargetOutOfRange {
89 /// The invalid target state.
90 target: usize,
91 /// Configured state count.
92 state_count: usize,
93 },
94
95 /// Same `(source, event)` maps to two different targets.
96 #[error(
97 "duplicate transition: {source_state} --{event}--> {existing_target} conflicts with {new_target}"
98 )]
99 DuplicateTransition {
100 /// Source state.
101 source_state: usize,
102 /// Event code.
103 event: usize,
104 /// Existing target.
105 existing_target: usize,
106 /// Conflicting target.
107 new_target: usize,
108 },
109}