Skip to main content

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    #[must_use]
42    #[inline]
43    pub(crate) fn new(complete: bool, failure_ids: Vec<FailureId>) -> Self {
44        Self { complete, failure_ids }
45    }
46
47    /// Returns whether every part of the outcome fit the configured limits.
48    ///
49    /// This reports collection completeness, not validation success. It is
50    /// `false` when a violation or skipped occurrence could not be retained.
51    #[must_use]
52    #[inline]
53    pub const fn complete(&self) -> bool {
54        self.complete
55    }
56
57    /// Returns IDs for failures retained from this outcome.
58    ///
59    /// Returns only failures newly retained from this outcome. Valid and
60    /// skipped outcomes return an empty slice; an invalid outcome can also
61    /// return an empty slice when no failure from it fit the report limit.
62    #[must_use]
63    #[inline]
64    pub fn failure_ids(&self) -> &[FailureId] {
65        &self.failure_ids
66    }
67}