use core::fmt;
use std::error::Error as StdError;
#[non_exhaustive]
#[derive(Debug)]
pub enum Error {
Other {
message: String,
source: Option<Box<dyn StdError + Send>>,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Other { message, source } => {
write!(f, "{message}")?;
if let Some(source) = source {
write!(f, ": {source}")?;
}
Ok(())
}
}
}
}
impl std::error::Error for Error {}
impl Error {
#[inline]
#[must_use]
pub fn message(message: String) -> Self {
Self::Other {
message,
source: None,
}
}
#[inline]
#[must_use]
pub fn other(message: String, source: Box<dyn StdError + Send>) -> Self {
Self::Other {
message,
source: Some(source),
}
}
}