qubit_value/numeric_comparison_error.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//! Errors that explain why runtime values cannot be numerically ordered.
10
11use qubit_datatype::DataType;
12use thiserror::Error;
13
14/// Describes why two [`crate::Value`] instances cannot be numerically ordered.
15///
16/// # Examples
17///
18/// ```
19/// use qubit_datatype::NumericComparisonPolicy;
20/// use qubit_value::{NumericComparisonError, Value};
21///
22/// let error = Value::from("text")
23/// .numeric_cmp(&Value::from(1_i32), NumericComparisonPolicy::Exact)
24/// .unwrap_err();
25/// assert!(matches!(error, NumericComparisonError::LeftNotNumeric { .. }));
26/// ```
27#[must_use]
28#[derive(Debug, Clone, PartialEq, Eq, Error)]
29#[non_exhaustive]
30pub enum NumericComparisonError {
31 /// The left operand is unset but retains a declared type.
32 #[error("left value is missing: declared type is {declared}")]
33 LeftMissing {
34 /// Declared runtime type of the unset left operand.
35 declared: DataType,
36 },
37 /// The right operand is unset but retains a declared type.
38 #[error("right value is missing: declared type is {declared}")]
39 RightMissing {
40 /// Declared runtime type of the unset right operand.
41 declared: DataType,
42 },
43 /// The concrete left operand is not numeric.
44 #[error("left value is not numeric: {actual}")]
45 LeftNotNumeric {
46 /// Actual runtime type of the left operand.
47 actual: DataType,
48 },
49 /// The concrete right operand is not numeric.
50 #[error("right value is not numeric: {actual}")]
51 RightNotNumeric {
52 /// Actual runtime type of the right operand.
53 actual: DataType,
54 },
55 /// Only the left operand is NaN.
56 #[error("left value is NaN")]
57 LeftNaN,
58 /// Only the right operand is NaN.
59 #[error("right value is NaN")]
60 RightNaN,
61 /// Both operands are NaN.
62 #[error("both values are NaN")]
63 BothNaN,
64}