#[derive(Debug)]
pub struct Error {
message: String,
}
impl Error {
pub fn msg(message: impl std::fmt::Display) -> Self {
Self {
message: message.to_string(),
}
}
pub(crate) fn context(context: &str, cause: impl std::fmt::Display) -> Self {
Self {
message: format!("{context}: {cause}"),
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(&self.message)
}
}
impl std::error::Error for Error {}
pub type Result<T> = std::result::Result<T, Error>;