use std::io::Error;
pub struct FinishError<T> {
error: Error,
writer: T,
}
impl<T> FinishError<T> {
pub(crate) const fn from_parts(error: Error, writer: T) -> Self {
Self { error, writer }
}
#[must_use]
pub const fn error(&self) -> &Error {
&self.error
}
#[must_use]
pub fn into_error(self) -> Error {
self.error
}
#[must_use]
pub fn into_inner(self) -> T {
self.writer
}
#[must_use]
pub fn into_parts(self) -> (Error, T) {
(self.error, self.writer)
}
}
impl<T> std::fmt::Debug for FinishError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("FinishError")
.field("error", &self.error)
.finish_non_exhaustive()
}
}
impl<T> std::fmt::Display for FinishError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "the stream could not be finished: {}", self.error)
}
}
impl<T> std::error::Error for FinishError<T> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.error)
}
}
impl<T> From<FinishError<T>> for Error {
fn from(value: FinishError<T>) -> Self {
value.error
}
}