use std::error::Error;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
#[must_use]
pub struct ContractWriterFailure<W> {
error: Box<dyn Error + Send>,
writer: W,
}
impl<W> ContractWriterFailure<W> {
pub fn error(&self) -> &(dyn Error + Send + 'static) {
self.error.as_ref()
}
pub const fn writer(&self) -> &W {
&self.writer
}
pub fn writer_mut(&mut self) -> &mut W {
&mut self.writer
}
pub fn into_parts(self) -> (Box<dyn Error + Send>, W) {
(self.error, self.writer)
}
pub(crate) fn new(error: impl Error + Send + 'static, writer: W) -> Self {
Self {
error: Box::new(error),
writer,
}
}
}
impl<W> Debug for ContractWriterFailure<W> {
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str("ContractWriterFailure { writer: retained, error: retained }")
}
}
impl<W> Display for ContractWriterFailure<W> {
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str("streaming writer failed; original error and recovery writer retained")
}
}
impl<W> Error for ContractWriterFailure<W> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(self.error.as_ref())
}
}