Skip to main content

qubit_codec/value/
value_codec_registry_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
9//! Value-codec registry errors.
10
11use thiserror::Error;
12
13use crate::ValueCodecRegistrationSource;
14
15/// Failure while freezing a value-codec registry.
16///
17/// Freezing rejects a registry that has two registrations under one stable
18/// ID, and reports the first conflicting ID together with the two declaration
19/// sites that form the first conflicting pair.
20///
21/// # Examples
22///
23/// ```
24/// use qubit_codec::ValueCodecRegistrationSource;
25/// use qubit_codec::ValueCodecRegistryError;
26///
27/// let error = ValueCodecRegistryError::DuplicateId {
28///     id: "example.u32",
29///     sources: vec![ValueCodecRegistrationSource::new(
30///         "qubit-codec",
31///         "my_crate::codecs",
32///         "src/codec.rs",
33///         42,
34///     )],
35/// };
36/// assert!(error.to_string().starts_with("duplicate value codec ID example.u32"));
37/// ```
38#[derive(Clone, Debug, Error)]
39#[must_use]
40pub enum ValueCodecRegistryError {
41    /// Multiple registrations claim one stable ID.
42    #[error("duplicate value codec ID {id} from {sources:?}")]
43    DuplicateId {
44        /// Conflicting stable ID.
45        id: &'static str,
46        /// Registration sources in deterministic order.
47        sources: Vec<ValueCodecRegistrationSource>,
48    },
49}