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
// =============================================================================
// Copyright (c) 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Provider-side asynchronous file write sessions.
use std::pin::Pin;
use qubit_io::AsyncOutput;
use super::SpiFuture;
use crate::error::FsResult;
use crate::metadata::WriteOutcome;
use crate::write::WriteAbortOutcome;
use crate::write::WriteFailure;
/// Provider session underlying a concrete [`crate::write::AsyncFileWriter`]
/// handle.
///
/// # Examples
///
/// ```
/// use qubit_fs::spi::AsyncFileWriteSession;
///
/// fn accepts_session<T: AsyncFileWriteSession>() {}
/// ```
pub trait AsyncFileWriteSession: AsyncOutput<Item = u8> + Send {
/// Asynchronously publishes bytes accepted by the session.
///
/// # Returns
/// A future resolving to the actual publication method and atomicity, or a
/// typed failure that preserves provider-confirmed publication progress.
///
/// # Errors
/// Resolves to a typed write failure when publication cannot be confirmed.
fn commit_async<'a>(self: Pin<&'a mut Self>) -> SpiFuture<'a, Result<WriteOutcome, WriteFailure>>;
/// Asynchronously cancels and cleans up this write session.
///
/// # Returns
/// A future resolving when cleanup is confirmed.
///
/// # Errors
/// Resolves to the provider cleanup failure with filesystem context.
fn abort_async<'a>(self: Pin<&'a mut Self>) -> SpiFuture<'a, FsResult<WriteAbortOutcome>>;
/// Performs nonblocking local cancellation during writer drop.
///
/// The default does nothing. Implementations must not start or block an
/// executor, wait for network I/O, or claim remote cleanup completed.
///
/// # Parameters
/// - `self`: Pinned provider session being abandoned.
#[inline]
fn cancel_on_drop(self: Pin<&mut Self>) {}
}