Skip to main content

qubit_json/decode/
json_number_token_error.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Errors from exact-safe-integer conversion.
9
10/// Why a validated number cannot be represented as a safe integer.
11#[non_exhaustive]
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum JsonNumberTokenError {
14    /// The token has a non-integral mathematical value.
15    Fractional,
16    /// The integer is outside the inclusive safe-integer range.
17    OutOfSafeIntegerRange,
18}
19
20impl std::fmt::Display for JsonNumberTokenError {
21    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            Self::Fractional => formatter.write_str("number is fractional"),
24            Self::OutOfSafeIntegerRange => formatter.write_str("integer is outside the safe range"),
25        }
26    }
27}
28
29impl std::error::Error for JsonNumberTokenError {}