Skip to main content

qubit_json/encode/
json_serialization_error_category.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//! Defines broad handling categories for strict JSON value encoding failures.
9
10/// Stable strategy category for a strict JSON value encoding failure.
11///
12/// # Examples
13///
14/// ```
15/// use qubit_json::encode::JsonSerializationError;
16/// use qubit_json::encode::JsonSerializationErrorCategory;
17/// use qubit_json::encode::JsonSerializationErrorKind;
18///
19/// let error = JsonSerializationError::new(JsonSerializationErrorKind::NonFiniteFloat);
20/// assert_eq!(error.category(), JsonSerializationErrorCategory::Number);
21/// ```
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
23pub enum JsonSerializationErrorCategory {
24    /// A numeric value violated the strict JSON number contract.
25    Number,
26    /// A JSON object key could not be represented unambiguously.
27    ObjectKey,
28    /// A RawValue payload violated the strict materialization contract.
29    RawValue,
30    /// A collection count exceeded the platform quantity representation.
31    Capacity,
32    /// A hand-written serializer or display implementation violated its
33    /// contract.
34    SerializerContract,
35    /// A serializer returned an opaque custom failure.
36    Custom,
37}