qubit-fs 0.2.2

Provider-neutral synchronous and asynchronous filesystem abstraction for Rust
Documentation
// =============================================================================
//    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>) {}
}