Skip to main content

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    /// # Errors
77    ///
78    /// Returns the formatter's error if writing the category fails.
79    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
80        let name = match self {
81            Self::UnknownParameter => "unknown parameter",
82            Self::DuplicateParameter => "duplicate parameter",
83            Self::MissingParameter => "missing parameter",
84            Self::ParameterAlreadyConsumed => "parameter already consumed",
85            Self::ParameterTypeMismatch => "parameter type mismatch",
86            Self::ParameterOutOfRange => "parameter out of range",
87            Self::InvalidBounds => "invalid bounds",
88            Self::InvalidPattern => "invalid pattern",
89            Self::MissingRule => "missing rule",
90            Self::UnsupportedInput => "unsupported input",
91            Self::MissingDependencyDeclaration => "missing dependency declaration",
92            Self::UnknownDependencyDeclaration => "unknown dependency declaration",
93            Self::DependencyOrderMismatch => "dependency order mismatch",
94            Self::PreparedSignatureMismatch => "prepared signature mismatch",
95            Self::DependencyOptionalityMismatch => "dependency optionality mismatch",
96            Self::DependencyTypeMismatch => "dependency type mismatch",
97            Self::UnreadablePath => "unreadable path",
98            Self::AmbiguousSignature => "ambiguous signature",
99            Self::UnsupportedConstraint => "unsupported constraint",
100            Self::MissingFeature => "missing feature",
101            Self::InvalidDeclaration => "invalid declaration",
102            Self::InvalidSelection => "invalid selection",
103        };
104        formatter.write_str(name)
105    }
106}