qubit_validator/binding/bind_error_kind.rs
1// =============================================================================
2// Copyright (c) 2025 - 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9//! Binding error kinds.
10
11use std::fmt;
12
13/// A configuration or declaration error found while binding a rule.
14///
15/// # Examples
16///
17/// ```
18/// use qubit_validator::BindErrorKind;
19///
20/// let kind = BindErrorKind::MissingParameter;
21/// assert_eq!(kind.to_string(), "missing parameter");
22/// ```
23#[must_use]
24#[derive(Clone, Copy, Debug, Eq, PartialEq)]
25#[non_exhaustive]
26pub enum BindErrorKind {
27 /// A parameter name is not known to the rule.
28 UnknownParameter,
29 /// A parameter was supplied more than once.
30 DuplicateParameter,
31 /// A required parameter is absent.
32 MissingParameter,
33 /// A parameter has already been consumed by this reader.
34 ParameterAlreadyConsumed,
35 /// A parameter has the wrong value type.
36 ParameterTypeMismatch,
37 /// A parameter is outside the supported range.
38 ParameterOutOfRange,
39 /// Bounds are internally inconsistent.
40 InvalidBounds,
41 /// A pattern cannot be compiled.
42 InvalidPattern,
43 /// The requested rule is not registered.
44 MissingRule,
45 /// A registered rule cannot consume the requested input.
46 UnsupportedInput,
47 /// A dependency declaration is missing.
48 MissingDependencyDeclaration,
49 /// A dependency declaration is unknown.
50 UnknownDependencyDeclaration,
51 /// Dependency declarations do not follow the signature's slot order.
52 DependencyOrderMismatch,
53 /// A prepared implementation disagrees with its declared signature.
54 PreparedSignatureMismatch,
55 /// A required dependency may be absent on a statically known path.
56 DependencyOptionalityMismatch,
57 /// A dependency has the wrong type.
58 DependencyTypeMismatch,
59 /// A dependency path cannot be read.
60 UnreadablePath,
61 /// More than one signature matches the declaration.
62 AmbiguousSignature,
63 /// A declared constraint has no implementation.
64 UnsupportedConstraint,
65 /// An implementation feature is disabled.
66 MissingFeature,
67 /// A declaration is malformed.
68 InvalidDeclaration,
69 /// A requested selection is not known.
70 InvalidSelection,
71}
72
73impl fmt::Display for BindErrorKind {
74 /// Formats the stable human-readable error category.
75 ///
76 /// # Parameters
77 ///
78 /// - `formatter`: Destination that receives the formatted category.
79 ///
80 /// # Errors
81 ///
82 /// Returns the formatter's error if writing the category fails.
83 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
84 let name = match self {
85 Self::UnknownParameter => "unknown parameter",
86 Self::DuplicateParameter => "duplicate parameter",
87 Self::MissingParameter => "missing parameter",
88 Self::ParameterAlreadyConsumed => "parameter already consumed",
89 Self::ParameterTypeMismatch => "parameter type mismatch",
90 Self::ParameterOutOfRange => "parameter out of range",
91 Self::InvalidBounds => "invalid bounds",
92 Self::InvalidPattern => "invalid pattern",
93 Self::MissingRule => "missing rule",
94 Self::UnsupportedInput => "unsupported input",
95 Self::MissingDependencyDeclaration => "missing dependency declaration",
96 Self::UnknownDependencyDeclaration => "unknown dependency declaration",
97 Self::DependencyOrderMismatch => "dependency order mismatch",
98 Self::PreparedSignatureMismatch => "prepared signature mismatch",
99 Self::DependencyOptionalityMismatch => "dependency optionality mismatch",
100 Self::DependencyTypeMismatch => "dependency type mismatch",
101 Self::UnreadablePath => "unreadable path",
102 Self::AmbiguousSignature => "ambiguous signature",
103 Self::UnsupportedConstraint => "unsupported constraint",
104 Self::MissingFeature => "missing feature",
105 Self::InvalidDeclaration => "invalid declaration",
106 Self::InvalidSelection => "invalid selection",
107 };
108 formatter.write_str(name)
109 }
110}