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
// =============================================================================
// Copyright (c) 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
// facade.
//! Provider write failure facts.
use crate::error::FsError;
use crate::write::WriteFailureState;
/// Typed provider write failure preserving recovery state.
///
/// # Examples
///
/// ```rust
/// use qubit_fs::error::{FsError, FsErrorKind, FsOperation};
/// use qubit_fs::spi::SpiWriteFailure;
/// use qubit_fs::write::WriteFailureState;
///
/// let failure = SpiWriteFailure::new(
/// FsError::new(FsErrorKind::Io, FsOperation::Write, "failed"),
/// WriteFailureState::NotPublished,
/// );
/// assert_eq!(WriteFailureState::NotPublished, failure.state());
/// ```
pub struct SpiWriteFailure {
/// Provider failure with filesystem context.
error: FsError,
/// Provider-confirmed publication and recovery state.
state: WriteFailureState,
}
impl SpiWriteFailure {
/// Creates a typed provider write failure.
///
/// # Parameters
/// - `error`: Provider failure with filesystem context.
/// - `state`: Provider-confirmed publication state.
///
/// # Returns
/// A failure containing both facts.
#[inline]
#[must_use]
pub fn new(error: FsError, state: WriteFailureState) -> Self {
Self { error, state }
}
/// Returns the underlying error.
///
/// # Returns
/// The provider failure with filesystem context.
#[inline]
#[must_use]
pub const fn error(&self) -> &FsError {
&self.error
}
/// Returns confirmed publication state.
///
/// # Returns
/// The provider-confirmed publication state.
#[inline]
#[must_use]
pub const fn state(&self) -> WriteFailureState {
self.state
}
/// Returns owned failure parts.
///
/// # Returns
/// The provider error and confirmed publication state.
#[inline]
#[must_use]
pub fn into_parts(self) -> (FsError, WriteFailureState) {
(self.error, self.state)
}
}
#[cfg(test)]
mod tests {
use super::SpiWriteFailure;
use crate::error::FsError;
use crate::error::FsErrorKind;
use crate::error::FsOperation;
use crate::write::WriteFailureState;
#[test]
fn failure_facts_are_executed_at_runtime() {
let failure = SpiWriteFailure::new(
FsError::new(FsErrorKind::Io, FsOperation::CommitWriter, "commit failed"),
WriteFailureState::Published,
);
assert_eq!(failure.error().kind(), FsErrorKind::Io);
assert_eq!(failure.state(), WriteFailureState::Published);
let (error, state) = failure.into_parts();
assert_eq!(error.kind(), FsErrorKind::Io);
assert_eq!(state, WriteFailureState::Published);
}
}