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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// =============================================================================
// Copyright (c) 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
// facade.
//! Provider copy failure facts.
use crate::copy::CopyFailureState;
use crate::copy::CopyStats;
use crate::error::FsError;
/// Typed provider copy failure reserved for copy orchestration.
///
/// # Examples
///
/// ```rust
/// use qubit_fs::copy::CopyFailureState;
/// use qubit_fs::copy::CopyStats;
/// use qubit_fs::error::{FsError, FsErrorKind, FsOperation};
/// use qubit_fs::spi::SpiCopyFailure;
///
/// let failure = SpiCopyFailure::new(
/// FsError::new(FsErrorKind::Io, FsOperation::Copy, "failed"),
/// CopyFailureState::Unchanged,
/// CopyStats::default(),
/// );
/// assert_eq!(CopyFailureState::Unchanged, failure.state());
/// ```
pub struct SpiCopyFailure {
/// Provider failure with filesystem context.
error: Box<FsError>,
/// Provider-confirmed destination publication state.
state: CopyFailureState,
/// Transfer progress confirmed before failure.
partial_stats: CopyStats,
}
impl SpiCopyFailure {
/// Creates a typed provider copy failure.
///
/// # Parameters
/// - `error`: Provider failure with filesystem context.
/// - `state`: Provider-confirmed publication state.
/// - `partial_stats`: Transfer progress confirmed before failure.
///
/// # Returns
/// A failure containing all provider-confirmed facts.
#[inline]
#[must_use]
pub fn new(error: FsError, state: CopyFailureState, partial_stats: CopyStats) -> Self {
Self {
error: Box::new(error),
state,
partial_stats,
}
}
/// Returns the provider error without exposing a recovery writer.
///
/// # Returns
/// The provider failure with filesystem context.
#[inline]
#[must_use]
pub fn error(&self) -> &FsError {
&self.error
}
/// Returns the typed publication state.
///
/// # Returns
/// The provider-confirmed publication state.
#[inline]
#[must_use]
pub const fn state(&self) -> CopyFailureState {
self.state
}
/// Splits this failure into its typed facts.
///
/// # Returns
/// The provider error, publication state, and partial transfer statistics.
#[inline]
#[must_use]
pub fn into_parts(self) -> (FsError, CopyFailureState, CopyStats) {
(*self.error, self.state, self.partial_stats)
}
}
#[cfg(test)]
mod tests {
use super::SpiCopyFailure;
use crate::copy::CopyFailureState;
use crate::copy::CopyStats;
use crate::error::FsError;
use crate::error::FsErrorKind;
use crate::error::FsOperation;
#[test]
fn failure_facts_are_executed_at_runtime() {
let failure = SpiCopyFailure::new(
FsError::new(FsErrorKind::NotFound, FsOperation::Copy, "missing source"),
CopyFailureState::PartiallyPublished,
CopyStats {
bytes: 4,
..CopyStats::default()
},
);
assert_eq!(failure.error().kind(), FsErrorKind::NotFound);
assert_eq!(failure.state(), CopyFailureState::PartiallyPublished);
let (error, state, stats) = failure.into_parts();
assert_eq!(error.kind(), FsErrorKind::NotFound);
assert_eq!(state, CopyFailureState::PartiallyPublished);
assert_eq!(stats.bytes, 4);
}
}