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.
// =============================================================================
// facade tests.
//! Typed facade rename failure.

use std::error::Error;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;

use crate::error::FsError;
use crate::rename::RenameFailureState;

/// A rename failure that preserves the provider's publication-state fact.
///
/// # Examples
///
/// ```rust
/// use qubit_fs::error::{FsError, FsErrorKind, FsOperation};
/// use qubit_fs::rename::{RenameFailure, RenameFailureState};
///
/// assert!(std::any::type_name::<RenameFailure>().contains("RenameFailure"));
/// let error = FsError::new(FsErrorKind::NotFound, FsOperation::Rename, "missing");
/// assert_eq!(RenameFailureState::Unchanged, RenameFailureState::Unchanged);
/// assert_eq!(FsOperation::Rename, error.operation());
/// ```
pub struct RenameFailure {
    /// Contextual filesystem error that interrupted the rename.
    error: FsError,
    /// Provider-confirmed source and destination transition state.
    state: RenameFailureState,
}
impl RenameFailure {
    /// Creates a typed facade rename failure.
    #[must_use]
    pub(crate) const fn new(error: FsError, state: RenameFailureState) -> Self {
        Self { error, state }
    }
    /// Returns the contextual filesystem error.
    #[inline]
    #[must_use]
    pub const fn error(&self) -> &FsError {
        &self.error
    }
    /// Returns the state of the source/target transition at failure.
    #[inline]
    #[must_use]
    pub const fn state(&self) -> RenameFailureState {
        self.state
    }
    /// Splits the failure into its error and state.
    #[inline]
    #[must_use]
    pub fn into_parts(self) -> (FsError, RenameFailureState) {
        (self.error, self.state)
    }
}
impl Debug for RenameFailure {
    /// Formats the safe typed failure facts.
    #[inline]
    fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
        formatter
            .debug_struct("RenameFailure")
            .field("error", &self.error)
            .field("state", &self.state)
            .finish()
    }
}

impl Display for RenameFailure {
    /// Formats the wrapped file-system error.
    #[inline]
    fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
        Display::fmt(&self.error, formatter)
    }
}

impl Error for RenameFailure {
    /// Returns the underlying file-system error.
    #[inline]
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        Some(&self.error)
    }
}