Skip to main content

qubit_json/encode/
json_serializer_state_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//! Defines violations of the Serde compound-serialization protocol.
9
10/// Invalid state produced by a malformed hand-written Serde implementation.
11///
12/// # Examples
13///
14/// ```
15/// use qubit_json::encode::JsonSerializationError;
16/// use qubit_json::encode::JsonSerializationErrorKind;
17/// use qubit_json::encode::JsonSerializerStateError;
18///
19/// let error = JsonSerializationError::new(JsonSerializationErrorKind::InvalidSerializerState {
20///     reason: JsonSerializerStateError::MapValueWithoutKey,
21/// });
22/// assert_eq!(
23///     error.serializer_state_error(),
24///     Some(JsonSerializerStateError::MapValueWithoutKey),
25/// );
26/// ```
27#[must_use]
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
29pub enum JsonSerializerStateError {
30    /// A compound callback was used with the wrong compound state, including
31    /// an element, key, or field callback after declaring a zero-length
32    /// compound.
33    UnexpectedCompound,
34    /// A split-map key was submitted before the previous key received a value.
35    MapKeyAlreadyPending,
36    /// A split-map value was submitted without a preceding key.
37    MapValueWithoutKey,
38    /// A split map ended while one key was still waiting for its value.
39    MapEndedWithPendingKey,
40    /// The private serde_json RawValue protocol had an invalid shape.
41    InvalidRawValueProtocol,
42    /// The private serde_json Number protocol had an invalid shape.
43    InvalidNumberProtocol,
44}