1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// =============================================================================
// Copyright (c) 2025 - 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Opaque identities for failures retained by one validation report.
use AtomicU64;
use Ordering;
/// Identifies one retained failure within its originating report.
///
/// IDs are issued by [`super::ValidationReport::record_outcome`]. A caller
/// cannot construct an ID, and a report rejects IDs issued by another report.
///
/// # Examples
///
/// ```
/// use qubit_validator::FailureId;
/// use qubit_validator::ValidationOutcome;
/// use qubit_validator::ValidationPath;
/// use qubit_validator::ValidationReport;
/// use qubit_validator::ValidatorId;
/// use qubit_validator::Violation;
/// use qubit_validator::ViolationCode;
///
/// let mut report = ValidationReport::new();
/// let outcome = report.record_outcome(
/// 0,
/// ValidationPath::root(),
/// ValidationOutcome::invalid(vec![Violation::new(
/// ValidatorId::new("text.required"),
/// ViolationCode::new("text.blank"),
/// )])?,
/// )?;
/// let failure: FailureId = outcome.failure_ids()[0];
/// assert!(report.failure(failure).is_some());
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Allocates a unique process-local identity for a new report.
///
/// # Panics
///
/// Panics when assigning the next identity would overflow `u64`, after
/// `u64::MAX - 1` report identities have been issued.
pub