use std::{error::Error, fmt};
pub type HttmResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;
#[derive(Debug)]
pub struct HttmError {
pub details: String,
}
impl HttmError {
pub fn new(msg: &str) -> Self {
HttmError {
details: msg.to_owned(),
}
}
pub fn with_context(msg: &str, err: Box<dyn Error + Send + Sync>) -> Self {
let msg_plus_context = format!("{} : {:?}", msg, err);
HttmError {
details: msg_plus_context,
}
}
}
impl fmt::Display for HttmError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.details)
}
}
impl Error for HttmError {
fn description(&self) -> &str {
&self.details
}
}