qubit_fs/write/writer_recovery.rs
1// =============================================================================
2// Copyright (c) 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Ownership retained after an aggregate write or copy failure.
9
10use std::fmt::Debug;
11use std::fmt::Formatter;
12use std::fmt::Result as FmtResult;
13
14use crate::write::FileWriter;
15use crate::write::RejectedWriter;
16
17/// A retained session that is either validated or restricted to explicit
18/// cleanup.
19///
20/// Matching the variant is required before performing recovery. A rejected
21/// session cannot write or publish data. This value does not describe the
22/// historical publication state; use the failure snapshot for that fact.
23///
24/// # Examples
25///
26/// ```rust
27/// use qubit_fs::write::WriterRecovery;
28///
29/// fn observe(_recovery: WriterRecovery) {}
30/// ```
31#[must_use]
32pub enum WriterRecovery {
33 /// A validated writer retained for explicit recovery.
34 Opened(Box<FileWriter>),
35 /// A provider session whose returned identity failed validation.
36 Rejected(RejectedWriter),
37}
38
39impl Debug for WriterRecovery {
40 /// Formats the variant without exposing provider session internals.
41 fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
42 formatter.write_str(match self {
43 Self::Opened(_) => "WriterRecovery::Opened",
44 Self::Rejected(_) => "WriterRecovery::Rejected",
45 })
46 }
47}