use std::fmt;
#[derive(Debug)]
pub struct Error {
message: String,
}
impl Error {
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
#[must_use]
pub fn message(&self) -> &str {
&self.message
}
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.message)
}
}
impl std::error::Error for Error {}
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Self::new(error.to_string())
}
}
pub type Result<T> = std::result::Result<T, Error>;
macro_rules! fail {
($($argument:tt)*) => {
return Err($crate::error::Error::new(format!($($argument)*)))
};
}
pub(crate) use fail;