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#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
28pub enum JsonSerializerStateError {
29 /// A compound callback was used with the wrong compound state.
30 UnexpectedCompound,
31 /// A split-map key was submitted before the previous key received a value.
32 MapKeyAlreadyPending,
33 /// A split-map value was submitted without a preceding key.
34 MapValueWithoutKey,
35 /// A split map ended while one key was still waiting for its value.
36 MapEndedWithPendingKey,
37 /// The private serde_json RawValue protocol had an invalid shape.
38 InvalidRawValueProtocol,
39}