Skip to main content

qubit_validator/
validator_id_error.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9//! Validator ID errors.
10
11use thiserror::Error;
12
13/// A stable validator ID protocol violation.
14///
15/// # Examples
16///
17/// ```
18/// use qubit_validator::{ValidatorId, ValidatorIdError};
19///
20/// let error = ValidatorId::try_new("rules..required").unwrap_err();
21/// assert_eq!(error, ValidatorIdError::EmptySegment);
22/// ```
23#[must_use]
24#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
25#[non_exhaustive]
26pub enum ValidatorIdError {
27    /// The complete ID is empty.
28    #[error("validator ID cannot be empty")]
29    Empty,
30    /// One dot-separated segment is empty.
31    #[error("validator ID contains an empty segment")]
32    EmptySegment,
33    /// One segment contains an invalid character or initial byte.
34    #[error("validator ID contains an invalid segment")]
35    InvalidSegment,
36}