use std::error::Error;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
use crate::copy::CopyFailureState;
use crate::copy::CopyStats;
use crate::error::FsError;
#[must_use = "inspect the asynchronous copy failure and its publication state"]
pub struct AsyncCopyFailure {
error: FsError,
state: CopyFailureState,
partial_stats: CopyStats,
}
impl AsyncCopyFailure {
pub(crate) fn new(error: FsError, state: CopyFailureState, partial_stats: CopyStats) -> Self {
Self {
error,
state,
partial_stats,
}
}
#[inline]
#[must_use = "inspect the filesystem error instead of discarding it"]
pub const fn error(&self) -> &FsError {
&self.error
}
#[inline]
pub const fn state(&self) -> CopyFailureState {
self.state
}
#[inline]
pub const fn partial_stats(&self) -> &CopyStats {
&self.partial_stats
}
#[inline]
pub fn into_parts(self) -> (FsError, CopyFailureState, CopyStats) {
(self.error, self.state, self.partial_stats)
}
}
impl Debug for AsyncCopyFailure {
#[inline]
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter
.debug_struct("AsyncCopyFailure")
.field("error", &self.error)
.field("state", &self.state)
.field("partial_stats", &self.partial_stats)
.finish()
}
}
impl Display for AsyncCopyFailure {
#[inline]
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
Display::fmt(self.error(), formatter)
}
}
impl Error for AsyncCopyFailure {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(self.error())
}
}