#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ErrorSummary {
inner: Box<SummaryInner>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
struct SummaryInner {
kind: &'static str,
area: &'static str,
message: String,
cancelled: bool,
}
impl ErrorSummary {
#[must_use]
pub fn kind(&self) -> &'static str {
self.inner.kind
}
#[must_use]
pub fn area(&self) -> &'static str {
self.inner.area
}
#[must_use]
pub fn message(&self) -> &str {
&self.inner.message
}
#[must_use]
pub fn is_cancelled(&self) -> bool {
self.inner.cancelled
}
}
impl From<&super::Error> for ErrorSummary {
fn from(err: &super::Error) -> Self {
Self {
inner: Box::new(SummaryInner {
kind: err.kind_name(),
area: err.area(),
message: err.to_string(),
cancelled: err.is_cancelled(),
}),
}
}
}
impl From<super::Error> for ErrorSummary {
fn from(err: super::Error) -> Self {
Self::from(&err)
}
}
impl std::fmt::Display for ErrorSummary {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.inner.message)
}
}
impl std::error::Error for ErrorSummary {}