qubit_json/format/json_pretty_error_kind.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//! Categories of JSON token formatting failures.
9
10use std::fmt;
11
12/// Stable category for a token formatting failure.
13#[non_exhaustive]
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15pub enum JsonPrettyErrorKind {
16 /// The input is not one complete syntactically valid JSON value.
17 Syntax,
18 /// The formatted bytes exceed the caller-provided maximum.
19 OutputLimit,
20 /// Checked length arithmetic or allocation could not be completed.
21 Capacity,
22 /// The output rejected a write; an accepted prefix may remain.
23 Io,
24}
25
26impl fmt::Display for JsonPrettyErrorKind {
27 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
28 formatter.write_str(match self {
29 Self::Syntax => "invalid JSON syntax",
30 Self::OutputLimit => "formatted output limit exceeded",
31 Self::Capacity => "formatting capacity exceeded",
32 Self::Io => "formatted output write failed",
33 })
34 }
35}