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.
31 UnexpectedCompound,
32 /// A split-map key was submitted before the previous key received a value.
33 MapKeyAlreadyPending,
34 /// A split-map value was submitted without a preceding key.
35 MapValueWithoutKey,
36 /// A split map ended while one key was still waiting for its value.
37 MapEndedWithPendingKey,
38 /// The private serde_json RawValue protocol had an invalid shape.
39 InvalidRawValueProtocol,
40}