qubit_validator/report/recorded_outcome.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//! Receipt returned after recording one validation outcome.
10
11use super::FailureId;
12
13/// Describes whether an outcome fit the report limits and identifies its
14/// retained failures.
15///
16/// # Examples
17///
18/// ```
19/// use qubit_validator::{RecordedOutcome, ValidationOutcome, ValidationPath, ValidationReport};
20///
21/// let mut report = ValidationReport::new();
22/// let receipt: RecordedOutcome = report.record_outcome(
23/// 0,
24/// ValidationPath::root(),
25/// ValidationOutcome::valid(),
26/// )?;
27/// assert!(receipt.complete());
28/// assert!(receipt.failure_ids().is_empty());
29/// # Ok::<(), Box<dyn std::error::Error>>(())
30/// ```
31#[derive(Clone, Debug, Eq, PartialEq)]
32pub struct RecordedOutcome {
33 /// Whether all outcome data could be retained within the report limits.
34 complete: bool,
35 /// Failure identifiers retained while recording this outcome.
36 failure_ids: Vec<FailureId>,
37}
38
39impl RecordedOutcome {
40 /// Creates a receipt for report recording.
41 ///
42 /// # Parameters
43 ///
44 /// - `complete`: whether all outcome data fit within the report limits.
45 /// - `failure_ids`: identifiers of failures retained from the outcome.
46 #[must_use]
47 #[inline]
48 pub(crate) fn new(complete: bool, failure_ids: Vec<FailureId>) -> Self {
49 Self { complete, failure_ids }
50 }
51
52 /// Returns whether every part of the outcome fit the configured limits.
53 ///
54 /// This reports collection completeness, not validation success. It is
55 /// `false` when a violation or skipped occurrence could not be retained.
56 #[must_use]
57 #[inline]
58 pub const fn complete(&self) -> bool {
59 self.complete
60 }
61
62 /// Returns IDs for failures retained from this outcome.
63 ///
64 /// Returns only failures newly retained from this outcome. Valid and
65 /// skipped outcomes return an empty slice; an invalid outcome can also
66 /// return an empty slice when no failure from it fit the report limit.
67 #[must_use]
68 #[inline]
69 pub fn failure_ids(&self) -> &[FailureId] {
70 &self.failure_ids
71 }
72}