use std::error::Error;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
use qubit_fs::copy::AsyncCopyFailure;
use qubit_fs::copy::AsyncCopyOperation;
use qubit_fs::error::FsError;
#[must_use]
pub struct ContractAsyncCopyFailure {
failure: AsyncCopyFailure,
operation: Option<AsyncCopyOperation>,
}
impl ContractAsyncCopyFailure {
pub const fn error(&self) -> &FsError {
self.failure.error()
}
pub const fn failure(&self) -> &AsyncCopyFailure {
&self.failure
}
pub const fn operation(&self) -> Option<&AsyncCopyOperation> {
self.operation.as_ref()
}
pub fn operation_mut(&mut self) -> Option<&mut AsyncCopyOperation> {
self.operation.as_mut()
}
pub fn into_parts(self) -> (AsyncCopyFailure, Option<AsyncCopyOperation>) {
(self.failure, self.operation)
}
pub(crate) fn new(failure: AsyncCopyFailure, operation: Option<AsyncCopyOperation>) -> Self {
Self { failure, operation }
}
}
impl Debug for ContractAsyncCopyFailure {
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter
.debug_struct("ContractAsyncCopyFailure")
.field("has_operation", &self.operation.is_some())
.finish_non_exhaustive()
}
}
impl Display for ContractAsyncCopyFailure {
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str("copy operation failed; original failure and available operation retained")
}
}
impl Error for ContractAsyncCopyFailure {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&self.failure)
}
}